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
相关推荐
chian-ocean32 分钟前
零基础入门:用C++从零实现TCP Socket网络小工具
网络·c++·tcp/ip
我不要放纵1 小时前
LVS集群搭建
linux·服务器·lvs
阿巴~阿巴~1 小时前
自主Shell命令行解释器
linux·运维·服务器
SHUIPING_YANG1 小时前
根据用户id自动切换表查询
java·服务器·数据库
chao_7892 小时前
更灵活方便的初始化、清除方法——fixture【pytest】
服务器·自动化测试·python·pytest
枷锁—sha2 小时前
【DVWA系列】——CSRF——Medium详细教程
android·服务器·前端·web安全·网络安全·csrf
枷锁—sha2 小时前
跨站请求伪造漏洞(CSRF)详解
运维·服务器·前端·web安全·网络安全·csrf
scuter_yu2 小时前
腾讯云云服务器深度介绍
服务器·云计算·腾讯云
guts°2 小时前
10-ACL技术
网络·网络协议
群联云防护小杜2 小时前
深度隐匿源IP:高防+群联AI云防护防绕过实战
运维·服务器·前端·网络·人工智能·网络协议·tcp/ip