我有这个service
文件:
[Unit]
Description=MyService
[Service]
User=root
WorkingDirectory=/path/to/workingdir
ExecStart=/path/to/myservice
[Install]
WantedBy=multi-user.target
当我myservice
从命令行启动时,它会启动并取消恶魔化。当我用-d
(用于调试)启动它时,它不会去恶魔化,但在按 Enter 时停止。
但是,当我将其放入文件myservice
中时service
,它根本不会启动:
[root@localhost bin]# systemctl status myservice.service
● myservice.service - MyService
Loaded: loaded (/etc/systemd/system/myservice.service; enabled; vendor preset: disabled)
Active: inactive (dead) since Tue 2023-08-22 09:20:21 CEST; 4min 1s ago
Process: 1790032 ExecStart=/path/to/myservice (code=exited, status=0/SUCCESS)
Main PID: 1790032 (code=exited, status=0/SUCCESS)
Aug 22 09:20:21 localhost.localdomain systemd[1]: Started MyService
Aug 22 09:20:21 localhost.localdomain myservice[1790033]: myservice started with:
Aug 22 09:20:21 localhost.localdomain myservice[1790033]: current working dir: /path/to/workingdir
Aug 22 09:20:21 localhost.localdomain systemd[1]: myservice.service: Succeeded.
当使用 启动它时-d
,它会启动,但 CPU 使用率会提高到 90%。
我应该如何service
为自己守护进程的程序配置文件?