Systemd 服务,我想创建但失败了。这是我创建的服务。
[Unit]
Description=rqworker daemon
After=network.target
[Service]
Type=simple
WorkingDirectory=/home/ubuntu/mamster
User=ubuntu
Group=ubuntu
#EnvironmentFile=/etc/sysconfig/master.env
#Environment="PYTHONPATH=/home/ubuntu/venv"
ExecStart=/home/ubuntu/venv /venv/bin/rqworker master
StandardOutput=/home/ubuntu/logs/icengine/std_out.log
StandardError=/home/ubuntu/logs/icengine/std_err/log
#SyslogIdentifier=icengin
KillMode=process
Restart=always
TimeoutSec=infinity
RestartPreventExitStatus=255
Type=notify
[Install]
WantedBy=multi-user.target
Alias=master.service
最初这项服务Actiating(Start)
是Active
但在我做了一些更改之后,现在显示错误:
跑步后sudo systemctl start rq
(venv) ubuntu@ubuntucalc:~$ sudo systemctl status rq
● rq.service - rqworker daemon
Loaded: loaded (/etc/systemd/system/rq.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Tue 2019-01-15 06:53:20 UTC; 4s ago
Process: 18537 ExecStart=/home/ubuntu/venv /venv/bin/rqworker master (code=exited, status=200/CHDIR)
Main PID: 18537 (code=exited, status=200/CHDIR)
Jan 15 06:53:20 ubuntucalc systemd[1]: rq.service: Main process exited, code=exited, status=200/CHDIR
Jan 15 06:53:20 ubuntucalc systemd[1]: rq.service: Failed with result 'exit-code'.
Jan 15 06:53:20 ubuntucalc systemd[1]: Failed to start rqworker daemon.
Jan 15 06:53:20 ubuntucalc systemd[1]: rq.service: Service hold-off time over, scheduling restart.
Jan 15 06:53:20 ubuntucalc systemd[1]: rq.service: Scheduled restart job, restart counter is at 5.
Jan 15 06:53:20 ubuntucalc systemd[1]: Stopped rqworker daemon.
Jan 15 06:53:20 ubuntucalc systemd[1]: rq.service: Start request repeated too quickly.
Jan 15 06:53:20 ubuntucalc systemd[1]: rq.service: Failed with result 'exit-code'.
Jan 15 06:53:20 ubuntucalc systemd[1]: Failed to start rqworker daemon.
这是我得到的输出。谢谢
答案1
该单元文件中存在一些问题:
- 该文件包含两个 实例
Type=
,一个带有simple
,另一个带有notify
。它必须只包含一行,并且 必须是正确的类型,而这又取决于可执行文件的行为方式/home/ubuntu/venv
。对于守护进程,通常forking
使用 。 - 给出的文件名
StandardError
应该是/home/ubuntu/logs/icengine/std_err.log
而不是/home/ubuntu/logs/icengine/std_err/log
。确保用户ubuntu
能够写入该位置并且目录存在。我认为systemd
如果不存在路径,则不会创建路径(尽管它会创建文件)。 StandardOutput=
和的语法StandardError=
是错误的。根据文档系统是StandardOutput=file:/home/ubuntu/logs/icengine/std_out.log
。 也一样StandardError
。