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
相关推荐
小乖写代码22 分钟前
提交注册验证 · WhatsApp /v2/register
android·网络·账号注册
多弗朗皮卡丘1 小时前
网络基础:数据链路层与其他协议或技术
linux·网络·tcp/ip
速捷工控 PLC触摸屏还原程序5 小时前
欧姆龙NB上传密码忘了,换屏前怎么保留原程序?
运维·服务器·欧姆龙
爱勇宝6 小时前
SSL 证书别再手动续了:acme.sh + Let's Encrypt + 云厂商 DNS 全自动实战
运维·服务器
我不会插花弄玉6 小时前
9.数据链路层【由浅入深-网络】
网络
wacsii8 小时前
【Linux进程(五)】进程控制全解析:从创建、终止、等待到程序替换
linux·服务器
七夜zippoe9 小时前
Nexent Linux 部署:用 deploy.sh
linux·服务器·docker·部署·ai智能体·nexent
去码头整点薯条989 小时前
NFS服务器
linux·运维·服务器
蜗牛一步步往上爬10 小时前
第一章 初识Linux shell
linux·运维·服务器
无足鸟ICT10 小时前
【RHCA+】系统调优配置文件
linux·服务器