linux用systemd运行二进制

前言

最近买了台vps,1c512m,系统是debian

我准备在这台vps上运行未来我用golang写的项目的演示站

在别的服务器都是用docker运行,但是这台服务器cpu和内存的原因,我就想用系统来运行

开始

先将二进制文件上传到服务器并赋予执行权限

然后写入systemd文件,并运行即可

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
cat << EOF > /etc/systemd/system/hertz_service.service
[Unit]
Description=hertz_service

[Service]
ExecStart=/root/hertz_service --config=config.yaml
WorkingDirectory=/root/
Restart=always
RestartSec=10
KillSignal=SIGINT
SyslogIdentifier=something-web-service
User=root

[Install]
WantedBy=multi-user.target
EOF

systemctl daemon-reload
systemctl enable hertz_service --now