【Linux】简单systemctl配置流程
文章目录
目录:/lib/systemd/system
文件:xyz.system
文件内容(极简):
[Unit]
Description=xyz
[Service]
ExecStart=/bin/bash -c "xyz >> xyz.log 2>&1"
Restart=always
[Install]
WantedBy=multi-user.targetUnit部分不解释
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
评论
登录后参与技术讨论,分享你的经验与见解。
登录 / 注册暂无评论