在centos7下使用systemctl加入自建服务

以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

猜你喜欢

转载自blog.csdn.net/u011922760/article/details/78805674