CentOS 7設定開機啟動服務,新增自訂系統服務
<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>
2.儲存目錄
以754的權限保存在目錄:
<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>
3.設定開機自啟動
nginx服務<code>/usr/lib/systemd/<span>system</span></code>設定開機自啟動
<code>systemctl enable nginx<span>.service</span></code>停止開機自啟動
<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>查看所有已啟動的服務