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
Release: 2016-07-29 08:49:50
Original
1215 people have browsed it

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>
Copy after login

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>
Copy after login

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>
Copy after login

2. Save the directory

Save in the directory with 754 permissions:

<code>/usr/lib/systemd/<span>system</span></code>
Copy after login

3. Set up auto-start on boot

Execute in any directory

<code>systemctl enable nginx<span>.service</span></code>
Copy after login
Copy after login

4. Other commands

Start nginx service

<code>systemctl <span><span>start</span> nginx.service</span></code>
Copy after login

Set up auto-start at boot

<code>systemctl enable nginx<span>.service</span></code>
Copy after login
Copy after login

Stop auto-start at boot

<code>systemctl disable nginx<span>.service</span></code>
Copy after login

View the current status of the service

<code>systemctl status nginx<span>.service</span></code>
Copy after login

Restart the service

<code>systemctl restart nginx<span>.service</span></code>
Copy after login

View all started services

<code>systemctl <span>list</span>-units --<span><span>type</span>=</span>service</code>
Copy after login
').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.

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template