用systemd脚本自动启动node js程序

vi /usr/lib/systemd/system/pano.service

[Unit]
Description=pano - main site of site_name.com
Documentation=http://www.site_name.com/docs/

[Service]
ExecStart=/usr/local/bin/node /www/www.site_name.com/node/bin/www
ExecStop=/bin/kill -s QUIT $MAINPID
Restart=always
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=nobody
User=nobody
Group=nobody
Environment=NODE_ENV=production

[Install]
WantedBy=multi-user.target
# systemctl enable pano
# systemctl start pano

nginx的启动脚本/usr/lib/systemd/system/nginx.service

[Unit]
Description=nginx - high performance web server
Documentation=http://nginx.org/en/docs/
After=network.target remote-fs.target nss-lookup.target
 
[Service]
Type=forking
PIDFile=/run/nginx.pid
ExecStartPre=/usr/sbin/nginx -t -c /etc/nginx/nginx.conf
ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
 
[Install]
WantedBy=multi-user.target
原文地址:https://www.cnblogs.com/afxcn/p/4013714.html