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.
这是我得到的输出。谢谢
该单元文件中有一些问题:
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=
是错误的。根据文档,sysntax 是StandardOutput=file:/home/ubuntu/logs/icengine/std_out.log
. 对StandardError
.