我有一个名为“ Informer”的应用程序。我正在尝试将其注册为服务,但不确定哪里出了问题。
以下是notifyer.service:
[Unit]
Description=Informer Docker
After=docker.service
Requires=docker.service
[Service]
Type=oneshot
User=root
WorkingDirectory=/opt/Informer5 <===Modify for the appropriate directory
ExecStart=/opt/Informer5/informer5.sh start <===Modify for the appropriate directory
ExecStop=/opt/Informer5/informer5.sh stop <===Modify for the appropriate directory
RemainAfterExit=yes
[Install]
WantedBy=multi-user.target
此文件在我的/ etc / systemd / system文件夹中。我已通过
启用了该服务 sudo systemctl enable informer
我执行时
sudo systemctl start informer
我得到的答复是
Job for informer.service failed because the control process exited with error code. See "systemctl status informer.service" and "journalctl -xe" for details.
因此,在运行systemctl status informer.service
时,我看到以下内容:
$sudo systemctl status informer.service
● informer.service - Informer Docker
Loaded: loaded (/etc/systemd/system/informer.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Tue 2018-09-18 08:49:07 EDT; 4min 2s ago
Process: 5780 ExecStart=/opt/Informer5/informer5.sh start <===Modify for the appropriate directory (code=exited, status=200/CHDIR)
Main PID: 5780 (code=exited, status=200/CHDIR)
Sep 18 08:49:07 informer5 systemd[1]: Starting Informer Docker...
Sep 18 08:49:07 informer5 systemd[1]: informer.service: Main process exited, code=exited, status=200/CHDIR
Sep 18 08:49:07 informer5 systemd[1]: Failed to start Informer Docker.
Sep 18 08:49:07 informer5 systemd[1]: informer.service: Unit entered failed state.
Sep 18 08:49:07 informer5 systemd[1]: informer.service: Failed with result 'exit-code'.
运行$ sudo journalctl -xe
,我得到:
$ sudo journalctl -xe
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit informer.service has failed.
--
-- The result is failed.
Sep 18 08:06:36 informer5 systemd[1]: informer.service: Unit entered failed state.
Sep 18 08:06:36 informer5 systemd[1]: informer.service: Failed with result 'exit-code'.
Sep 18 08:06:36 informer5 sudo[5690]: pam_unix(sudo:session): session closed for user root
Sep 18 08:12:40 informer5 sudo[5712]: n_connor : TTY=pts/0 ; PWD=/opt/Informer5 ; USER=root ; COMMAND=/bin/cat /etc/systemd/system/informer.service
Sep 18 08:12:40 informer5 sudo[5712]: pam_unix(sudo:session): session opened for user root by n_connor(uid=0)
Sep 18 08:12:40 informer5 sudo[5712]: pam_unix(sudo:session): session closed for user root
Sep 18 08:15:01 informer5 CRON[5716]: pam_unix(cron:session): session opened for user root by (uid=0)
Sep 18 08:15:01 informer5 CRON[5717]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Sep 18 08:15:01 informer5 CRON[5716]: pam_unix(cron:session): session closed for user root
Sep 18 08:17:01 informer5 CRON[5721]: pam_unix(cron:session): session opened for user root by (uid=0)
Sep 18 08:17:01 informer5 CRON[5722]: (root) CMD ( cd / && run-parts --report /etc/cron.hourly)
Sep 18 08:17:01 informer5 CRON[5721]: pam_unix(cron:session): session closed for user root
Sep 18 08:25:01 informer5 CRON[5732]: pam_unix(cron:session): session opened for user root by (uid=0)
Sep 18 08:25:01 informer5 CRON[5733]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Sep 18 08:25:01 informer5 CRON[5732]: pam_unix(cron:session): session closed for user root
Sep 18 08:35:01 informer5 CRON[5745]: pam_unix(cron:session): session opened for user root by (uid=0)
Sep 18 08:35:01 informer5 CRON[5746]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Sep 18 08:35:01 informer5 CRON[5745]: pam_unix(cron:session): session closed for user root
Sep 18 08:45:01 informer5 CRON[5758]: pam_unix(cron:session): session opened for user root by (uid=0)
Sep 18 08:45:01 informer5 CRON[5759]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Sep 18 08:45:01 informer5 CRON[5758]: pam_unix(cron:session): session closed for user root
Sep 18 08:47:43 informer5 sudo[5774]: n_connor : TTY=pts/0 ; PWD=/opt/Informer5 ; USER=root ; COMMAND=/bin/cat /etc/systemd/system/informer.service
Sep 18 08:47:43 informer5 sudo[5774]: pam_unix(sudo:session): session opened for user root by n_connor(uid=0)
Sep 18 08:47:43 informer5 sudo[5774]: pam_unix(sudo:session): session closed for user root
Sep 18 08:49:07 informer5 sudo[5777]: n_connor : TTY=pts/0 ; PWD=/opt/Informer5 ; USER=root ; COMMAND=/bin/systemctl start informer
Sep 18 08:49:07 informer5 sudo[5777]: pam_unix(sudo:session): session opened for user root by n_connor(uid=0)
Sep 18 08:49:07 informer5 systemd[5780]: informer.service: Failed at step CHDIR spawning /opt/Informer5/informer5.sh: No such file or directory
-- Subject: Process /opt/Informer5/informer5.sh could not be executed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- The process /opt/Informer5/informer5.sh could not be executed and failed.
--
-- The error number returned by this process is 2.
Sep 18 08:49:07 informer5 systemd[1]: Starting Informer Docker...
-- Subject: Unit informer.service has begun start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit informer.service has begun starting up.
Sep 18 08:49:07 informer5 systemd[1]: informer.service: Main process exited, code=exited, status=200/CHDIR
Sep 18 08:49:07 informer5 systemd[1]: Failed to start Informer Docker.
-- Subject: Unit informer.service has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit informer.service has failed.
--
-- The result is failed.
Sep 18 08:49:07 informer5 systemd[1]: informer.service: Unit entered failed state.
Sep 18 08:49:07 informer5 systemd[1]: informer.service: Failed with result 'exit-code'.
Sep 18 08:49:07 informer5 sudo[5777]: pam_unix(sudo:session): session closed for user root
Sep 18 08:53:09 informer5 sudo[5787]: n_connor : TTY=pts/0 ; PWD=/opt/Informer5 ; USER=root ; COMMAND=/bin/systemctl status informer.service
Sep 18 08:53:09 informer5 sudo[5787]: pam_unix(sudo:session): session opened for user root by n_connor(uid=0)
Sep 18 08:53:09 informer5 systemd[1]: Configuration file /etc/systemd/system/informer.service is marked executable. Please remove executable permission bits. Proceeding anyway.
Sep 18 08:53:09 informer5 sudo[5787]: pam_unix(sudo:session): session closed for user root
Sep 18 08:54:01 informer5 sudo[5791]: n_connor : TTY=pts/0 ; PWD=/opt/Informer5 ; USER=root ; COMMAND=/bin/journalctl -xe
Sep 18 08:54:01 informer5 sudo[5791]: pam_unix(sudo:session): session opened for user root by n_connor(uid=0)
我认为这里的主要错误是informer.service: Failed at step CHDIR spawning /opt/Informer5/informer5.sh: No such file or directory
我已检查该文件确实存在,并且可以使用该文件作为根来手动启动该服务。我在服务文件中设置了主目录。我不知道这个错误是从哪里来的。我正在使用ubuntu 16.04,并且已通过ssh启用了root登录。有什么想法吗?
答案 0 :(得分:0)
我在顶部的bash文件中添加了#!/ bin / bash,它可以正常工作 例如
nano server.sh
#!/bin/bash
echo "Serving Web App!"
serve -s build -p 4004
chmod + x server.sh
nano /etc/systemd/system/web.service
[Unit]
Description=Web App
After=network.target
[Service]
WorkingDirectory=/var/www/html/web
User=root
ExecStart=/var/www/html/web/server.sh
Restart=on-failure
[Install]
WantedBy=multi-user.target
注意事项