Cam*_*ros 9 startup arch-linux systemd
我正在运行 Arch Linux。我有/etc/systemd/system/
以下描述的服务
[Unit]
After=network.target
[Service]
Type=simple
ExecStart=(...)service.py
ExecReload=(...)service.py
Restart=always
Run Code Online (Sandbox Code Playgroud)
我将它设置为在网络建立后启动,因为它取决于网络连接。
当我启动 PC 时,该服务始终处于非活动状态。如果我手动启动它运行完美。如果出现一些内部错误,它也会重新启动。为什么开机不启动?
编辑
启用该服务时,我收到此消息:
? ~ systemctl enable py_service.service
The unit files have no installation config (WantedBy, RequiredBy, Also, Alias
settings in the [Install] section, and DefaultInstance for template units).
This means they are not meant to be enabled using systemctl.
Possible reasons for having this kind of units are:
1) A unit may be statically enabled by being symlinked from another unit's
.wants/ or .requires/ directory.
2) A unit's purpose may be to act as a helper for some other unit which has
a requirement dependency on it.
3) A unit may be started when needed via activation (socket, path, timer,
D-Bus, udev, scripted systemctl call, ...).
4) In case of template units, the unit is meant to be enabled with some
instance name specified.`
Run Code Online (Sandbox Code Playgroud)
关于这些点:
它没有符号链接
它不是帮手
我以为这是由 After=network...
我不知道这是什么意思
编辑 2按照@dustball 的建议,我编辑为:
cat /etc/systemd/system/py_service.service
[Install]
WantedBy=multi-user.target
[Unit]
After=network.target
[Service]
Type=simple
ExecStart=(...)service.py
ExecReload=(...)service.py
Restart=always
Run Code Online (Sandbox Code Playgroud)
但它没有在启动时启动:(
编辑 3 上述配置有效,我忘记启用它(感谢@Daniel H)使用重新加载服务
sudo systemctl daemon-reload
Run Code Online (Sandbox Code Playgroud)
然后使用启用它
systemctl enable py_service.service
Run Code Online (Sandbox Code Playgroud)
小智 17
错误消息已经为您提供了答案(部分)。服务有一个 [Install] 部分。唯一的选项是“WantedBy=”。要启用服务,目标必须需要它。
示例:NetworkManager 有“WantedBy=network.target”,所以当你启用 NetworkManager 时,它被分组到 network.target 中,并在 systemd 启动 network.target 时立即启动
把它想象成 SysV-init 中的运行级别,一个守护进程必须插入一个运行级别,否则......它应该什么时候启动?
一个安全的默认值是设置“WantedBy=multi-user.target”,它是最后一个启动的。