使用 systemctl 创建服务
2025/11/2小于 1 分钟
使用 systemctl 创建服务
创建 service 文件
/etc/systemd/system/go-app.service内容:
[Unit]
Description=Go App Service
After=network.target
[Service]
Type=simple
WorkingDirectory=/data/www/go/new-world
ExecStart=/data/www/go/new-world/goapp
Restart=always
RestartSec=5
User=root
[Install]
WantedBy=multi-user.target重新加载 systemd
systemctl daemon-reload启动服务
systemctl start go-app设置开机启动
systemctl enable go-app日志查看
systemd 默认接管 stdout/stderr
查看:
journalctl -u go-app
实时:
journalctl -u go-app -f
最近100行:
journalctl -u go-app -n 100
你的 Go:
fmt.Println("hello")
会进入:journalctl