golang 守护进程管理

添加守护进程

vim /etc/systemd/system/xxx.service

sh 复制代码
[Unit]
Description=Go Socket Service
After=network.target

[Service]
Type=simple
ExecStart=/data/quwan/quwan_ws
WorkingDirectory=/data/quwan
# 停止前发送信号
ExecStop=/bin/kill -SIGTERM $MAINPID
# 如果超过20s 进程还没停止,则强制重启
TimeoutStopSec=20s
Restart=always
# 重启在1s后重启
RestartSec=1s
# 标准输出到固定文件
StandardOutput=append:/data/quwan/output.log
#StandardOutput=file:/data/quwan/output.log
StandardError=inherit

[Install]
WantedBy=multi-user.target

执行 sudo systemctl daemon-reload

使用脚本启动

sh 复制代码
#!/bin/sh

if [ "$1" = "status" ]; then
  # 只显示状态和版本信息
  ./mq_quwan -v
  systemctl status mq_baobao.service
else
  # 默认重启服务并显示状态
  ./mq_quwan -v
  systemctl restart mq_baobao.service
  systemctl status mq_baobao.service
fi


#sudo systemctl daemon-reload
# sudo systemctl start baobao_go.service
# sudo systemctl enable baobao_go.service
# sudo systemctl status baobao_go.service
相关推荐
小糖学代码2 小时前
网络:4.1加餐 - 进程间关系与守护进程
linux·网络
m***66733 小时前
【Sql Server】sql server 2019设置远程访问,外网服务器需要设置好安全组入方向规则
运维·服务器·安全
xinxinhenmeihao3 小时前
隧道代理和住宅IP有何不同》各有什么优缺点?
服务器·网络·tcp/ip
q***78373 小时前
【Golang】——Gin 框架中间件详解:从基础到实战
中间件·golang·gin
小兔薯了3 小时前
6. Linux 硬盘分区管理
linux·运维·服务器
努力的Andy3 小时前
Linux 云服务器新增硬盘:从分区、格式化到挂载的完整指南
linux·运维·服务器
裤裤兔3 小时前
linux卡在启动界面的解决办法
linux·运维·服务器·centos·centos7·linux系统
kka杰3 小时前
Linux:基础IO介绍-1
linux·运维·服务器
Xの哲學3 小时前
Linux slab分配器深度剖析:从原理到实践
linux·服务器·算法·架构·边缘计算
Murphy_lx4 小时前
Linux中信号量的相关操作
linux·运维·服务器