1·配置文件xxxx.service
[Unit]
Description=带有配置文件的App
[Service]
ExecStart=/www/demo.com/xxxx "-c" "/www/demo.com/配置文件"
Restart=always
RestartSec=120
[Install]
WantedBy=multi-user.target
[Unit]
Description=My Node.js App
After=network.target
[Service]
ExecStart=node绝对路径 /www/demo.com/server.js
Restart=always
Environment=PATH=/usr/bin:/usr/local/bin
Environment=NODE_ENV=production
WorkingDirectory=/www/demo.com
[Install]
WantedBy=multi-user.target
确保 node 命令的路径正确,可以通过
which node
2·文件目录
/etc/systemd/system
3·命令
1·设置开机自启动
systemctl enable xxxx
2·启动服务
systemctl start xxxx
service xxxx start
3·重启服务
systemctl restart xxxx
service xxxx restart
4·关闭服务
systemctl stop xxxx
service xxxx stop
5·检查状态
systemctl status xxxx
service xxxx status
6·重载配置
systemctl daemon-reload
systemctl reload xxxx
service xxxx reload