Gre*_*ine 19
用户服务的示例是描述如何执行此操作的最简单方法。
假设您有一个名为 的二进制文件或脚本mytask,您希望将其作为服务运行,并且它位于 中/usr/local/bin/。
在您的主目录 中创建一个systemd名为 的单元文件,其中包含以下内容:my_example.service~/.config/systemd/user/
[Unit]
Description=[My example task]
[Service]
Type=simple
StandardOutput=journal
ExecStart=/usr/local/bin/mytask
[Install]
WantedBy=default.target
Run Code Online (Sandbox Code Playgroud)
该行ExecStart是最相关的,因为您可以在该行中指定要运行的二进制文件或脚本的路径。
要使您的服务在启动时自动启动,请运行
systemctl --user enable my_example.service
Run Code Online (Sandbox Code Playgroud)
如果您想立即启动服务而不重新启动,请运行
systemctl --user start my_example.service
Run Code Online (Sandbox Code Playgroud)
如果你想停止服务,运行
systemctl --user stop my_example.service
Run Code Online (Sandbox Code Playgroud)
要检查服务的状态,请运行
systemctl --user status my_example.service
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6654 次 |
| 最近记录: |