systemd 脚本

#!/bin/bash

project_name="mygo"
project_path="/data/backend/"
exec_path="${project_path}${project_name}"

cat > /lib/systemd/system/${project_name}.service << EOF
[Unit]
Description=mygo systemd
Documentation=https://yezihack.github.io
After=network.target

[Service]
Type=simple
User=root
# 启动命令
ExecStart=${exec_path}
# 重启命令
ExecReload=/bin/kill -SIGINT 

# 环境变量
Environment="SGFOOT_ENV=pro"
Environment="SGFOOT_PATH=/data/conf"

KillMode=process
Restart=on-failure
RestartSec=3s

[Install]
WantedBy=multi-user.targe
EOF

管理

systemctl daemon-reload # 更新配置
systemctl start mygo # 启动
systemctl stop mygo # 停止
systemctl restart mygo # 重启
systemctl enable mygo # 加入开机启动

关于我

我的博客:https://yezihack.github.io

欢迎关注我的微信公众号【空树之空】,共同学习,一起进步~ 空树之空