CentOS 7.x allows you to set custom startup and add custom system services.

Source: Internet
Author: User

CentOS 7.x allows you to set custom startup and add custom system services.
Centos System Service Script directory: [html] view plaincopyprint?

  1. /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:

[Html] view plaincopyprint?
  1. /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 [html] view plaincopyprint?
  1. Vim/lib/systemd/system/nginx. service
[Plain] view plaincopyprint?
  1. [Unit]
  2. Description = nginx
  3. Afterdomainnetwork.tar get
  4. [Service]
  5. Type = forking
  6. ExecStart =/www/lanmps/init. d/nginxstart
  7. ExecReload =/www/lanmps/init. d/nginxrestart
  8. ExecStop =/www/lanmps/init. d/nginxstop
  9. PrivateTmp = true
  10. [Install]
  11. 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:

[Html] view plaincopyprint?
  1. /Lib/systemd/system
3. Set auto-start upon startup

[Html] view plaincopyprint?
  1. Systemctlenablengworkflow. service

4. Other commands

The new command of the old task command enables a service to automatically start chkconfig -- level 3 httpd on systemctl enable httpd. service causes a service to not automatically start chkconfig -- level 3 httpd offsystemctl disable httpd. service check service Status service httpd statussystemctl statushttpd. service (service details)
Systemctl is-active httpd. service (show Active only) display all started services chkconfig -- listsystemctl list-units -- type = service start a service httpd startsystemctl start httpd. service to stop a service httpd stopsystemctl stop httpd. restart a service httpd restartsystemctl restart httpd. service

Start the nginx Service

systemctlstartnginx.service

Set auto-start

systemctlenablenginx.service

Stop Auto-start

systemctldisablenginx.service

View Current Service Status

systemctlstatusnginx.service

Restart the service

systemctlrestartnginx.service

View all started services

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