Home  >  Article  >  Backend Development  >  CentOS 7 sets up startup service and adds custom system services centos 7 closes the firewall centos 7.2 centos 7 64-bit download

CentOS 7 sets up startup service and adds custom system services centos 7 closes the firewall centos 7.2 centos 7 64-bit download

WBOY
WBOYOriginal
2016-07-29 08:49:501191browse

CentOS 7 sets up startup service and adds custom system services

  • Create service file
  • save directory
  • Set auto-start at boot
  • Other commands

1. Create service file

File path

<code>vim /usr/lib/systemd/<span>system</span>/nginx.service </code>

Service File content

<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>

Explanation of file content

<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. Save the directory

Save in the directory with 754 permissions:

<code>/usr/lib/systemd/<span>system</span></code>

3. Set up auto-start on boot

Execute in any directory

<code>systemctl enable nginx<span>.service</span></code>

4. Other commands

Start nginx service

<code>systemctl <span><span>start</span> nginx.service</span></code>

Set up auto-start at boot

<code>systemctl enable nginx<span>.service</span></code>

Stop auto-start at boot

<code>systemctl disable nginx<span>.service</span></code>

View the current status of the service

<code>systemctl status nginx<span>.service</span></code>

Restart the service

<code>systemctl restart nginx<span>.service</span></code>

View all started services

<code>systemctl <span>list</span>-units --<span><span>type</span>=</span>service</code>
').addClass('pre-numbering ').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i ').text(i)); }; $numbering.fadeIn(1700); }); });

The above has introduced CentOS 7 to set up startup services and add custom system services, including centos 7 content. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn