systemd 脚本

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/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://www.sgfoot.com
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

管理

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

关于我

我的博客:https://www.sgfoot.com

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