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
相关推荐
其实防守也摸鱼11 小时前
CTF密码学综合教学指南--第五章
开发语言·网络·笔记·python·安全·网络安全·密码学
网络工程小王11 小时前
【LangChain 大模型6大调用指南】调用大模型篇
linux·运维·服务器·人工智能·学习
wangbing112511 小时前
各linux版本的包管理命令
linux·运维·服务器
S1998_1997111609•X12 小时前
论mysql国盾shell-sfa犯罪行为集团下的分项工程及反向注入原理尐深度纳米算法下的鐌檵鄐鉎行为
网络·数据库·网络协议·百度·开闭原则
比昨天多敲两行12 小时前
Linux基础开发工具(下)
linux·运维·服务器
AI精钢12 小时前
AI Agent 从上线到删库跑路始末
网络·人工智能·云原生·aigc
linux修理工13 小时前
chrome官方下载地址
运维·服务器
笨笨饿14 小时前
69_如何给自己手搓一个串口
linux·c语言·网络·单片机·嵌入式硬件·算法·个人开发
cn_lyg14 小时前
Linux的入门级常用操作命令
linux·运维·服务器
geneculture15 小时前
《智能通信速分多次传输技术(VDMT)》专利文件的全文汉英双语对照版本
服务器·网络·人工智能·融智学的重要应用·哲学与科学统一性·融智时代(杂志)·人机间性