SYSTEMD Add custom system service settings custom boot up

Source: Internet
Author: User

1. Service rights
SYSTEMD has system and user distinction; system (/user/lib/systemd/system/), User (/etc/lib/systemd/user/). unit files created manually by the general system administrator are recommended to be stored in the/etc/systemd/ Under the system/directory.
2. Create a service file
[Unit] Description=nginx-high Performance Web Serverdocumentation=http://nginx.org/en/docs/after=network.target Remote-fs.target Nss-lookup.target [service]type=forkingpidfile=/run/nginx.pidexecstartpre=/usr/sbin/nginx-t-C/ Etc/nginx/nginx.confexecstart=/usr/sbin/nginx-c/etc/nginx/nginx.confexecreload=/bin/kill-s HUP $MAINPIDExecStop = /bin/kill-s QUIT $MAINPIDPrivateTmp =true [install]wantedby=multi-user.target
[unit]description: A simple description of the service Documentation: Service document before, after: defines the boot order. Before=xxx.service, on behalf of the service, starts before Xxx.service starts. After=xxx.service, on behalf of the service after Xxx.service started. Requires: This unit starts, the unit it needs is also started, the unit it needs is stopped, and the unit is stopped. Wants: Recommended use. The unit is activated, the unit it needs is also started, and the unit it needs is stopped and has no effect on this unit.
[Service]type=simple (default): Systemd thinks the service will start immediately. The service process does not fork. If the service is to start another service, do not use this type to start unless the service is socket-activated. Type=forking:systemd believes that when the service process is fork and the parent process exits, the service starts successfully. For a regular daemon (daemon), use this type to start up unless you are sure that this startup mode does not meet your requirements. Use this startup type to specify pidfile= at the same time so that SYSTEMD can track the main process of tracking. Type=oneshot: This option applies to services that perform only one task and then exit immediately. You may need to set remainafterexit=yes at the same time so that Systemd still thinks the service is active after the service process exits. Type=notify: Same as Type=simple, but the contract service sends a signal to SYSTEMD when it is ready. The implementation of this notification is provided by libsystemd-daemon.so. Type=dbus: If started in this manner, when the specified busname appears on the Dbus system bus, SYSTEMD considers the service ready. Type=idle:systemd waits for all tasks to complete before starting to execute an idle type of cell. In addition, other behaviors are similar to type=simple. Pidfile:pid file path Execstart: Specifies the command or script for the startup unit, Execstartpre and Execstartpost sections specify scripts that the user customizes to execute before or after Execstart. Type=oneshot allows you to specify multiple user-defined commands that you want to execute sequentially. Execreload: Specifies the command or script to execute when the unit stops. Execstop: Specifies the command or script to execute when the unit stops. Privatetmp:true indicates that the service is assigned a separate temporary space restart: If this option is allowed, the process exits when the service restarts, and the cleanup and restart operation is performed through the Systemctl command. Remainafterexit: If this option is set to true, the service is considered to be active, even if the process has exited and the default value is false, this option needs to be configured only at Type=oneshot.
[Install]
Alias: Provides an additional name for the unit to separate space. Requiredby: The unit is allowed to run a series of dependent units required, and the Requiredby list obtains dependency information from require. Wantby: The unit is allowed to run the required weak dependency unit, Wantby to obtain dependency information from the want list. Also: Indicates the unit with which the Unit is installed or assisted. Defaultinstance: The limit of the instance unit, which specifies if the unit is allowed to run the default instance.
3. Heavy Duty Service
Systemctl Enable Nginx.service
A link to a new/usr/lib/systemd/system/nginx.service file is created under the/etc/systemd/system/multi-user.target.wants/directory.
4. Operation Service
#启动服务 $ sudo systemctl start nginx.service #查看日志 $ sudo journalctl-f-u nginx.service-logs begin at 42,015-06-25 17:32:20 Cst. -June 10:28:24 Leco.lan systemd[1]: Starting Nginx–high performance Web server ... June 10:28:24 Leco.lan nginx[7976]: nginx:the configuration file/etc/nginx/nginx.conf syntax is ok6 month 10:28:24 LECO.L An nginx[7976]: nginx:configuration file/etc/nginx/nginx.conf test is successful6 month 10:28:24 Leco.lan systemd[1]: Star Ted Nginx–high Performance Web server. #重启 $ sudo systemctl restart Nginx.service #重载 $ sudo systemctl reload nginx.service #停止 $ sudo systemctl stop Nginx.service

SYSTEMD Add custom system service settings custom boot up

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.