centos 7 设置Service

1. vim /lib/systemd/system/nginx.service

2.
 [Unit]  
Description=nginx  
After=network.target  
   
[Service]  
Type=forking  
ExecStart=/www/lanmps/init.d/nginx start  
ExecReload=/www/lanmps/init.d/nginx restart  
ExecStop=/www/lanmps/init.d/nginx  stop  
PrivateTmp=true  
   
[Install]  
WantedBy=multi-user.target 


3. systemctl enable nginx.service

systemd有系统和用户区分;系统(/usr/lib/systemd/system/)、用户(/usr/lib/systemd/user/)放置在系统目录中在开机中没有登陆情况下就能运行的程序;反之则放在用户目录中

[img]
http://dl2.iteye.com/upload/attachment/0115/3120/32422b67-0fc9-36f3-b371-2853ea855a20.png
[/img]


4.

启动nginx服务

systemctl start nginx.service

设置开机自启动

systemctl enable nginx.service

停止开机自启动

systemctl disable nginx.service

查看服务当前状态

systemctl status nginx.service

重新启动服务

systemctl restart nginx.service

查看所有已启动的服务

systemctl list-units --type=service

你可能感兴趣的:(centos 7 设置Service)