“Golang Gin 使用Systemd管理服务重启和防止挂掉”的版本间差异

本页内容
(创建页面,内容为“当我们将服务编译好后再线上需要长期保持进程一直工作,这个时候最好基于systemd去管理进程。 == Systemd 配置 == 添加下面内容到gin_app.service文件 <sample title="" desc=""> [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 </sample> <sample title=…”)
 
Neo讨论 | 贡献
无编辑摘要
 
第1行: 第1行:
[[分类:Golang Gin Web 框架教程]]
当我们将服务编译好后再线上需要长期保持进程一直工作,这个时候最好基于systemd去管理进程。
当我们将服务编译好后再线上需要长期保持进程一直工作,这个时候最好基于systemd去管理进程。



2022年9月28日 (三) 13:39的最新版本

当我们将服务编译好后再线上需要长期保持进程一直工作,这个时候最好基于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。