目录:/lib/systemd/system
文件:xyz.system
文件内容(极简):
[Unit]
Description=xyz
[Service]
ExecStart=/bin/bash -c "xyz >> xyz.log 2>&1"
Restart=always
[Install]
WantedBy=multi-user.target
Unit部分不解释
Service描述服务细节
ExecStart部分设置启动命令,systemctl会截流标stdout和stderr,所以用/bin/bash -c
包了一层,如果你的命令不往stdout和stderr写东西可以直接写你的命令
Restart可以配置重启选项,always表示检测到进程消失就肯定会重启
Install描述服务的安装方法
WantedBy部分表示该target启动时,service也会被启动
控制命令
// 重新加载配置文件
systemctl daemon-reload
// 启用或禁用服务
systemctl enable xyz.service
systemctl disable xyz.service
// 一般控制命令
systemctl start xyz.service
systemctl stop xyz.service
systemctl restrt xyz.service
systemctl status xyz.service
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。