Centos7系统中golang程序的配置及管理方案

2021-01-10 20:47:41

Centos7系统,加一个/lib/systemd/system/goapp.service 执行文件:

[Unit]
Description="golang app daemonize systemd"
After=network.target
After=network-online.target
Wants=network-online.target

[Service]
User=root
Group=root
Environment=GIN_MODE=release
WorkingDirectory=/opt/blog58
ExecStart=/bin/bash -c '/opt/blog58/app'

[Install]
WantedBy=multi-user.target

最后添加到开机启动:

[root@VM_0_5_centos ~]# systemctl enable goapp
Created symlink from /etc/systemd/system/multi-user.target.wants/goapp.service to /usr/lib/systemd/system/goapp.service.

重启系统后就可以看到服务已经在运行了。

golang程序