1 在 /etc/systemd/system/ 下创建服务, 如 goadmin.service
2 打开 goadmin.service, 编写如下命令 :
[Unit]
Description=Go Admin
After=network-online.target
Wants=network-online.target
[Service]
Type=simple
# 程序执行的目录
WorkingDirectory=/webs/***/
# 启动的脚本命令
ExecStart=/webs/***/main
# 重启条件
Restart=always
# 几秒后重启
RestartSec=5
[Install]
WantedBy=multi-user.target
systemctl enable goadmin.service
systemctl start goadmin.service
systemctl status goadmin.service
systemctl daemon-reload