使用 systemd 管理程序的一个简明示例
source link: https://hellodk.cn/post/352
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
使用 systemd 管理程序的一个简明示例
首先,推荐阮一峰老师的两篇文章:
Systemd 入门教程:命令篇 http://www.ruanyifeng.com/blog/2016/03/systemd-tutorial-commands.html
Systemd 入门教程:实战篇 http://www.ruanyifeng.com/blog/2016/03/systemd-tutorial-part-two.html
我打算将我本地使用的 qbittorrent-nox 服务 以及 frpc 的服务 (还有其他的) 配置成这样
一、以frpc为例
为 frpc 编写 frpc.service
sudo vim /etc/systemd/system/frpc.service
然后填入以下内容
[Unit]
Description=frpc service
[Service]
User=dk
Group=dk
ExecStart=/temp/frp_0.20.0_linux_amd64/frpc -c /temp/frp_0.20.0_linux_amd64/frpc.ini
Restart=always
Type=simple
[Install]
WantedBy=multi-user.target
设置开机自启
sudo systemctl enable frpc
启动 frpc 服务
sudo systemctl start frpc
一些其他命令
# 查看是否已设置开机自启
sudo systemctl is-enabled frpc
# 查看当前程序状态
sudo systemctl status frpc
# 查看服务状态
systemctl list-unit-files --type=service | grep frpc
二、 qbittorrent-nox
qbittorrent-nox 的service 配置文件如下:
[Unit]
Description=thinkpad t400 qbittorrent
[Service]
User=dk
Group=dk
ExecStart=/usr/bin/qbittorrent-nox
ExecStop=/usr/bin/killall qbittorrent-nox
Restart=always
Type=simple
[Install]
WantedBy=multi-user.target
注意: ExecStart=/usr/bin/qbittorrent-nox
中的命令路径必须是完整路径,虽然 qbittorrent-nox
在 shell 中也能正确执行,但在 systemd 的 service 配置文件中需要填写完整路径
注意: qbittorrent-nox 本身运行的是 dk 用户 在 Service 里 就用 dk 用户,使用 User
Group
标识,如果使用 root 或者其他用户 会导致qbittorrent启用其他的用户登录 (若之前没有配置 那么使用默认的 admin 用户登录)
标签: Linux
本作品采用 知识共享署名-相同方式共享 4.0 国际许可协议 进行许可。
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK