System services, power does not need to log on will be able to run (the equivalent of boot from Kai)
/ usr / lib / systemd / System
user services, programs need to be logged in to post run
/ usr / lib / systemd / user directory and there are two types of files:
* .service service unit files
* .target boot-level unit
Detailed profiles
The following is Nginx startup script
[Unit] Description=nginx - high performance web server Documentation=http://nginx.org/en/docs/ After=network.target remote-fs.target nss-lookup.target [Service] Type=forking User=nginx Group=nginx ExecStartPre=/usr/local/nginx/sbin/nginx -t ExecStart=/usr/local/nginx/sbin/nginx ExecReload=/usr/local/nginx/sbin/nginx -s reload ExecStop=/usr/local/nginx/sbin/nginx -s stop [Install] WantedBy=multi-user.target
[Unit]
Documentation Documentation Address
Description short description
Requires other current Unit Unit dependent, if they are not running, the current Unit fail to start
Wants to other current Unit Unit cooperate, if they are not running, the current Unit does not start failure
BindsTo and Requires Similarly, it specifies Unit If you quit, it will cause the current Unit stop running
before if the field specified Unit should start, you must start after the current Unit
after the field if the specified Unit should start before it must be in the current Unit start
Conflicts specified here Unit Unit can not run simultaneously with the current
condition ... Unit currently running conditions must be met, otherwise they would not run
conditions Assert ... Unit currently running must be met, otherwise it will fail to start newspaper
[Service] Type = forking represent background mode. The User = the User Settings service that runs user Group = the User Settings User Group services running the Restart = Always always restart RestartSec = 1 Restart the number of seconds PrivateTmp = to true representation to the service allocates a separate temporary space Environment specified environment variable
PIDFile specified service PID file ExecStart start of the current service command command is executed before the start of the current service ExecStartPre after ExecStartPost start of the current service commands executed command ExecReload executed when restarting the current service ExecStop stop command to be executed when the current service ExecStopPost stop command when the execution of its services KillMode current control group in all sub-processes will be killed
EnvironmentFile = / etc / sysconfig / sshd
stored in the form of key = value, $ key to read the form
before all the startup settings, you can add a conjunction sign (-), meaning "to suppress error", that is, when the error occurred does not affect the execution of other commands.
= EnvironmentFile - / etc / sysconfig / sshd (note that conjunctions number after the equal sign), it means that even if the / etc / sysconfig / sshd file does not exist, it will not throw an error.
Environment:
followed by the shell of a plurality of different variables, for example:
Environment data_dir = = / Data / Elk
Environment. LOG_DIR = = / var / log / elasticsearch
Environment = PID_DIR = / var / RUN / elasticsearch
EnvironmentFile = - / etc / sysconfig / elasticsearch
= Type the Simple defaults, ExecStart field to start the process of the main process forking ExecStart field will fork () way to start oneshot similar to the simple, but only once, Systemd will wait for it to finish execution before start other services, will Exex * BASH support behind the command syntax. dbus similar to the simple, but will wait D - start after Bus signals notify similar to the simple, notification will be issued after the start signal, and then restart other services Systemd idle like simple, but to wait until other tasks are executed, will not start the service. Is using the occasion to make the service output, the output is not mixed with other services
Restart = not restart no default value after exit ON - Success only when the normal exit (exit status 0), before restarting ON - when non-normal exit failure (non-zero), comprising a termination signal and time-out, restart will oN - Abnormal termination signal and only the timeout will restart oN - ABORT terminates only upon receipt of the signal is not captured, will restart oN - Watchdog timeout exit will restart always quit for whatever reason, always restart but not after the restart systemctl stop serviceName.service command to stop the service.
Exec * followed by the command, only to accept the "command Parameters .." format, can not accept <> | & other special characters, a lot of bash syntax is not supported. If you want to support bash syntax, you need to set Tyep = oneshot
KillMode = Control- Group default, the current control group in all sub-processes will be killed process only to kill the main process mixed primary process will receive the SIGTERM signal, the child received SIGKILL signal none no process will be killed, just execute service stop command
[Install] is usually the last block of the configuration file used to define how to start, and whether the boot. Its main fields are as follows. WantedBy = Multi- user.target # multiuser WantedBy: its value is one or more Target, the current Unit activated (enable) into symbolic link / etc / systemd / system to Target name + directory configured suffix .wants subdirectory RequiredBy: its value is one or more Target, the current Unit activated, symbolic link into / etc / systemd / system directory name to Target + subdirectory .required suffix configured Alias: current Unit It can be used to start an alias Also: the current Unit activation (enable), will be activated at the same time other Unit
WantedBy fields: WantedBy = Multi - user.targe: indicates multiuser command line, the setting is important graphical.target represents a graphical user-shaped body, which depends on the Multi -user.target