A list,
Centos7.4 Startup the first program from init completely changed to systemd this startup mode, with centos 5 6 is already a substantial difference. Systemd controls the startup service and the startup level by managing unit.
The /usr/lib/systemd/system directory contains various unit files, including service suffix unit, target boot level unit, etc. Because systemd in the boot to execute the boot, are through these *. Service unit control, services are divided into system services (system) and user services (user).
System service: a program that can run without logging in at boot (often used to boot from boot).
User services: need to login after the operation of the program.
Ii. Configuration File Description:
[UNIT] # Media wanager Service # After=network. Target [Service] The operation of the # define a Service Type, usually forking (background) Type = forking # define systemctl start | stop | reload *. The implementation of the Service method (specific orders need to write the absolute path) # note: ExecStartPre indicates the command executed before the startup. ExecStart=/opt/nginx/sbin/nginx ExecReload=/opt/nginx/sbin/nginx -s reload ExecStop=/opt/nginx/sbin/nginx -s stop # Create private memory temporary space PrivateTmp=True [Install] # multi-user WantedBy=multi-user. TargetCopy the code
[Unit] Block: Startup sequence and dependencies Description field: provides a brief Description of the current service. Documentation field: Gives the document location. After field: If network.target or sshd-keygen.service needs to start, then sshd.service should start After them. Before field: Defines which services sshd.service should start Before. Note: The After and Before fields only refer to the startup order, not dependencies. ExecStart: define the command to be executed when the process is started. ExecReload: define the command to be executed when the Service is restarted. ExecStartPre Field: Command executed before starting the service ExecStartPost field: command executed after starting the service ExecStopPost field: command executed after stopping the service All startup Settings can be preceded by a conjunction sign (-) to indicate "suppression error", that is, when an error occurs, it does not affect the execution of other commands. For example, EnvironmentFile=-/etc/sysconfig/sshd (note the conjunction after the equal sign) means that an error will not be thrown even if the /etc/sysconfig/sshd file does not exist. [Service] start/restart/stop commands all require absolute path. Startup Type The Type field defines the startup Type. The values it can set are as follows: simple (default) : The process started by the ExecStart field is the primary process. Forking: The ExecStart field will be started by fork(), at which point the parent will exit and the child will become the primary process (running in the background) oneshot: Similar to simple, but executed only once, Systemd waits for it to complete before starting other services dBUS: Similar to simple, but waits for a D-bus signal to start notify: Similar to Simple, the system starts other services idle after the start is complete. Similar to Simple, the service does not start until all other tasks are complete. PrivateTmp=True Assigns a separate temporary space to the service. [Install] Settings related to the installation of the service, which can be set to multi-user block. Define how to install the configuration file, that is, how to boot up. WantedBy field: Represents the Target of the service. Target is a service group, indicating a group of services. WantedBy=multi-user. Target Indicates that the target where the SSHD resides is multi-user. # this setting is important because a symbolic link to sshd.service is displayed when systemctl enable sshd.service is executed. It will be placed in the multi-user.target.wants subdirectory under /etc/systemd/system. Systemd has a default startup Target.Copy the code
Common commands
Service To start the service: systemctl start *. Service To stop the service: Systemctl stop *. Service Restart the service: systemctl reload *Copy the code