示例 /etc/systemd/system/myapp.service
示例 /etc/systemd/system/myapp.service
[Unit]
Description=MyApp Service
After=network-online.target
Wants=network-online.target
[Service]
Type=simple
User=appuser
WorkingDirectory=/opt/myapp
ExecStart=/opt/myapp/bin/myapp -c /etc/myapp/app.conf
Restart=on-failure
RestartSec=5
LimitNOFILE=65535
[Install]
WantedBy=multi-user.target上线流程
上线流程
systemctl daemon-reload
systemctl enable --now myapp.service
systemctl status myapp.service --no-pager -lExecStart 必须写绝对路径;老式脚本自行后台化的程序用 Type=forking 并配 PIDFile,前台进程用 Type=simple。