CentOS7 custom boot item

Source: Internet
Author: User

CentOS7 custom boot item

Centos System Service Script directory:

/Usr/lib/systemd/

There are systems and users,

If you need to start a program that can run without logging on to the system, it exists in the system service, namely:

/Lib/systemd/system/

Otherwise, the program that can run only after the user logs on exists in the user

The service ends with. service.

The following uses nginx as an example.

1. Create a service file

Vim/lib/systemd/system/nginx. service

[Unit]

Description = nginx

Afterdomainnetwork.tar get

[Service]

Type = forking

ExecStart =/www/lanmps/init. d/nginxstart

ExecReload =/www/lanmps/init. d/nginxrestart

ExecStop =/www/lanmps/init. d/nginx stop

PrivateTmp = true

[Install]

Wantedbypolicmulti-user.tar get

[Unit]: Service Description

Description: describes the service.

After: Describes the service category.

[Service] Service running parameter settings

Type = forking is the form of background running

ExecStart is the specific running command of the service.

ExecReload is the restart command

ExecStop is the Stop command

PrivateTmp = True indicates that an independent temporary space is allocated to the service.

Note: the absolute path is required for the [Service] startup, restart, and stop commands.

[Install] service installation settings, which can be set to multiple users

2. Save the Directory

Save as 754 permissions in the directory:

/Lib/systemd/system

3. Set auto-start upon startup

Systemctl enable nginx. service

4. Other commands

New commands of old task commands

Enable a service to automatically start chkconfig -- level 3 httpd on systemctl enable httpd. service

Make a service not automatically start chkconfig -- level3 httpd off systemctldisable httpd. service

Check service status servicehttpd status systemctlstatus httpd. service (service details)

Systemctlis-active httpd. service (only show whether it is Active)

Show all started services chkconfig -- list systemctllist-units -- type = service

Start a service servicehttpd start systemctlstart httpd. service

Stop a service servicehttpd stop systemctlstop httpd. service

Restart a service servicehttpd restart systemctlrestart httpd. service

Start the nginx Service

Systemctl start nginx. service

Set auto-start

Systemctl enable nginx. service

Stop Auto-start

Systemctl disable nginx. service

View Current Service Status

Systemctl status nginx. service

Restart the service

Systemctl restart nginx. service

View all started services

Systemctl list-units -- type = service

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.