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
相关推荐
库玛西几秒前
深入浅出Linux select网络模型:从底层位图原理到C++面向对象高级封装
linux·服务器·网络·c++·ubuntu
Tingjct2 分钟前
线程详细讲解---聚焦linux
linux·服务器·jvm
ComputerInBook17 分钟前
linux包管理工具——yum(YellowdogUpdaterModified)
linux·运维·服务器·yum·dnf
en.en..24 分钟前
Linux mmap 内存映射深度解析:基于帧缓冲 /dev/fb0
java·服务器·前端
实心儿儿30 分钟前
Linux —— epoll(1)
linux·网络
Soari40 分钟前
TSN网络之工业以太网协议测试
网络
s_w.h44 分钟前
【 计网 】序列化与反序列化
linux·服务器·网络·算法·bash
Boop_wu1 小时前
[LangGraph] 案例 2 : 支持搜索的智能代理系统
服务器·windows·python·langchain
物联通信量讯说1 小时前
5G会取代4G吗?物联网设备出海正在走向多网络融合
网络·物联网·5g
祖力551 小时前
网络编程:IO多路复用(select、poll、epoll)
linux·服务器·网络