Systemd 是 Linux 系统工具,用来启动守护进程,下面动手来给一个服务配置开启启动已经服务down掉自动重启
1.创建服务配置/etc/systemd/system/app.service
[Unit]
Description=govideo
[Service]
Type=simple
ExecStart=/bin/bash -c "cd /home/www/go && ./main"
# 重启条件
Restart=always
# 几秒后重启
RestartSec=5
[Install]
WantedBy=multi-user.target
2.重载服务
systemctl daemon-reload
3.启动服务
systemctl start app.service
4.最后执行以下来查看服务运行的状态信息
systemctl status app.service
5.执行以下命令将服务添加到开机启动项
systemctl enable app.service
常见的命令有: start(启动), stop(停止), restart(重启), status(查看运行状态), enable(添加到开机启动项), disable(将程序从开机启动中移除)