系统服务:发出方法调用失败:单元服务失败

我正在尝试在我的VPS中进行自定义服务。 但是,它不让我去运行它。 它说以下。 我不知道发生了什么事,但是当我在Ubuntu笔记本电脑上运行它时,它正常工作。 可能是什么问题呢?

sudo systemctl启动websocket.service

Failed to issue method call: Unit websocket.service failed to load: No such file or directory. See system logs and 'systemctl status websocket.service' for details. 

cat /lib/systemd/system/websocket.service

 [Unit] Description=php webSocket After=syslog.target network.target [Service] User=root Type=simple ExecStart=/usr/bin/webs.sh TimeoutStopSec=20 KillMode=process Restart=always RestartSec=2 [Install] WantedBy=multi-user.target Alias=websocket.service 

cat /usr/bin/webs.sh

 #!/bin/bash ### BEGIN INIT INFO # Provides: webSocket # Required-Start: $local_fs $network # Required-Stop: $local_fs # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: php webSocket # Description: php webSocket ### END INIT INFO /usr/bin/php /path/to/server.php 

我已经尝试过systemctl daemon-reload但我得到以下

 Attempted to remove disk file system, and we can't allow that. Ignoring /etc/systemd/system/multi-user.target.wants/ssh.service -> /lib/systemd/system/ssh.service for systemd deputy init Ignoring /etc/systemd/system/multi-user.target.wants/rsyslog.service -> /lib/systemd/system/rsyslog.service for systemd deputy init Ignoring /etc/systemd/system/multi-user.target.wants/bind9.service -> /lib/systemd/system/bind9.service for systemd deputy init Ignoring /etc/systemd/system/timers.target.wants/phpsessionclean.timer -> /lib/systemd/system/phpsessionclean.timer for systemd deputy init 

任何人都可以给我一些什么事情的暗示吗?

这是服务文件的权限:

 -rwxr-xr-x 1 root root 264 Feb 6 05:06 websocket.service* 

而这个为bash文件:

 -rwxr-xr-x 1 root root 349 Feb 6 05:02 webs.sh* 

我将webs.sh文件更改为/usr/bin/ path,并将文件更新为@TeroKilkanen,但仍然遇到同样的问题。

这里的一个问题是你将脚本添加到根目录,而不是脚本的地方。 /usr/local/bin是这样的脚本的更好的地方。

第二个问题是你的屁股是不正确的。 Shebang仅包含将用于执行脚本的可执行文件的path,而不包含任何参数。 这是什么导致No such file or directory. 错误。 https://unix.stackexchange.com/questions/63979/shebang-line-with-usr-bin-env-command-argument-fails-on-linux告诉更多关于这种行为。

您可以使用这种方法:

对于webs.sh使用这个:

 #!/bin/bash ### BEGIN INIT INFO # Provides: webSocket # Required-Start: $local_fs $network # Required-Stop: $local_fs # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: php webSocket # Description: php webSocket ### END INIT INFO /usr/bin/php /path/to/server.php 

请记住给该文件提供可执行的权限。

我不会担心迈克尔的评论,系统输出的其余部分可能是这个错误设置的症状。