CentOS 7设置开机启动服务,添加自定义系统服务
1.建立服务文件
文件路径
<code>vim /usr/lib/systemd/<span>system</span>/nginx.service </code>
服务文件内容
<code><span>[Unit]</span><span>Description=<span>nginx - high performance web server</span></span><span>After=<span>network.target remote-fs.target nss-lookup.target</span></span><span>[Service]</span><span>Type=<span>forking</span></span><span>ExecStart=<span>/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf</span></span><span>ExecReload=<span>/usr/local/nginx/sbin/nginx -s reload</span></span><span>ExecStop=<span>/usr/local/nginx/sbin/nginx -s stop</span></span><span>[Install]</span><span>WantedBy=<span>multi-user.target</span></span></code>
文件内容解释
<code>[<span>Unit</span>]:服务的说明<span> Description:描述服务</span><span> After:描述服务类别</span><span> [Service]服务运行参数的设置</span><span> Type=forking是后台运行的形式</span><span> ExecStart为服务的具体运行命令</span><span> ExecReload为重启命令</span><span> ExecStop为停止命令</span><span> PrivateTmp=True表示给服务分配独立的临时空间</span><span> 注意:启动、重启、停止命令全部要求使用绝对路径</span><span> [Install]服务安装的相关设置,可设置为多用户</span></code>
2.保存目录
以754的权限保存在目录:
<code>/usr/lib/systemd/<span>system</span></code>
3.设置开机自启动
任意目录下执行
<code>systemctl enable nginx<span>.service</span></code>
4.其他命令
<code>systemctl <span><span>start</span> nginx.service</span></code>
<code>systemctl enable nginx<span>.service</span></code>
<code>systemctl disable nginx<span>.service</span></code>
<code>systemctl status nginx<span>.service</span></code>
<code>systemctl restart nginx<span>.service</span></code>
<code>systemctl <span>list</span>-units --<span><span>type</span>=</span>service</code>
以上就介绍了CentOS 7设置开机启动服务,添加自定义系统服务,包括了centos 7方面的内容,希望对PHP教程有兴趣的朋友有所帮助。