linux中service模板

[Unit]
Description=描述
After=syslog.target network.target remote-fs.target nss-lookup.target
 
[Service]
Type=simple
WorkingDirectory=程序路径
User=root
ExecStart=/bin/sh -c "exec 执行程序(例:npm run xxx) >> 输出文件(例:xxx.log) 2>&1"
PrivateTmp=true
 
[Install]
WantedBy=multi-user.target

放在/etc/systemd/system目录下即可用systemctl start/stop命令启动停止服务了 (需要chmod授权一下)

原文地址:https://www.cnblogs.com/demonrain/p/9232605.html