linux用systemd运行二进制
发表于|更新于
|总字数:179|阅读时长:1分钟|浏览量:
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=hertz_service User=root
[Install] WantedBy=multi-user.target EOF
systemctl daemon-reload systemctl enable hertz_service --now
|
更新服务
1 2 3 4 5 6 7 8 9
| #!/bin/bash
app_full_path=/root/hertz_service download_url=https://xxx/hertz_service
rm -f ${app_full_path} wget ${download_url} -O ${app_full_path} chmod +x ${app_full_path} systemctl restart hertz_service
|