Golang Gin 使用Systemd管理服务重启和防止挂掉

本页内容

当我们将服务编译好后再线上需要长期保持进程一直工作,这个时候最好基于systemd去管理进程。

Systemd 配置

添加下面内容到gin_app.service文件


示例

[Unit]
Description=gin_app Service
After=network.target

[Service]
Type=simple
User=www
Restart=always
RestartSec=5s
ExecStart=gin_app
ExecReload=kill $(pidof gin_app) ;  gin_app

[Install]
WantedBy=multi-user.target


接着开启该服务

systemctl --user enable /home/app/gin_app.service


启动服务

systemctl start gin_app.service

重启服务

systemctl restart gin_app.service


关闭服务

systemctl restart gin_app.service
此页面最后编辑于2022年9月28日 (星期三) 13:39。