以nginx为例子
1 在/usr/lib/systemd/system/ 建立nginx.service文件 命令: touch /usr/lib/systemd/system/nginx.service
2 修改该文件 加入内容
[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
PATH=/usr/local/nginx
NAME=nginx
PIDFile=$PATH/logs/$NAME
ExecStartPre=$PATH/sbin/nginx -t -c $PATH/conf/nginx.conf
ExecStart=$PATH/sbin/nginx -c $PATH/conf/nginx.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
3 保存后重启机器
4 加入开机自启 systemctl enable nginx.service