-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstartup.service
More file actions
44 lines (39 loc) · 3.24 KB
/
startup.service
File metadata and controls
44 lines (39 loc) · 3.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# This file is about the systemd.
# After Ubuntu 16.04 initrd is no longer recommend but systemd
# Systemd will read configuration from /etc/systemd/system and this directory is will link to /usr/lib/systemd/system/ and "systemctl enable" will build the link
# A systemd file include three parts [Unit], [Service], [Install]
# Configurations of each parts like this:https://www.freedesktop.org/software/systemd/man/systemd.unit.html
# [Unit]区块通常是配置文件的第一个区块,用来定义 Unit 的元数据,以及配置与其他 Unit 的关系。它的主要字段如下。
# Description:简短描述
# Documentation:文档地址
# Requires:当前 Unit 依赖的其他 Unit,如果它们没有运行,当前 Unit 会启动失败
# Wants:与当前 Unit 配合的其他 Unit,如果它们没有运行,当前 Unit 不会启动失败
# BindsTo:与Requires类似,它指定的 Unit 如果退出,会导致当前 Unit 停止运行
# Before:如果该字段指定的 Unit 也要启动,那么必须在当前 Unit 之后启动
# After:如果该字段指定的 Unit 也要启动,那么必须在当前 Unit 之前启动
# Conflicts:这里指定的 Unit 不能与当前 Unit 同时运行
# Condition...:当前 Unit 运行必须满足的条件,否则不会运行
# Assert...:当前 Unit 运行必须满足的条件,否则会报启动失败
# [Install]通常是配置文件的最后一个区块,用来定义如何启动,以及是否开机启动。它的主要字段如下。
# WantedBy:它的值是一个或多个 Target,当前 Unit 激活时(enable)符号链接会放入/etc/systemd/system目录下面以 Target 名 + .wants后缀构成的子目录中
# RequiredBy:它的值是一个或多个 Target,当前 Unit 激活时,符号链接会放入/etc/systemd/system目录下面以 Target 名 + .required后缀构成的子目录中
# Alias:当前 Unit 可用于启动的别名
# Also:当前 Unit 激活(enable)时,会被同时激活的其他 Unit
# [Service]区块用来 Service 的配置,只有 Service 类型的 Unit 才有这个区块。它的主要字段如下。
# Type:定义启动时的进程行为。它有以下几种值。
# Type=simple:默认值,执行ExecStart指定的命令,启动主进程
# Type=forking:以 fork 方式从父进程创建子进程,创建后父进程会立即退出
# Type=oneshot:一次性进程,Systemd 会等当前服务退出,再继续往下执行
# Type=dbus:当前服务通过D-Bus启动
# Type=notify:当前服务启动完毕,会通知Systemd,再继续往下执行
# Type=idle:若有其他任务执行完毕,当前服务才会运行
# ExecStart:启动当前服务的命令
# ExecStartPre:启动当前服务之前执行的命令
# ExecStartPost:启动当前服务之后执行的命令
# ExecReload:重启当前服务时执行的命令
# ExecStop:停止当前服务时执行的命令
# ExecStopPost:停止当其服务之后执行的命令
# RestartSec:自动重启当前服务间隔的秒数
# Restart:定义何种情况 Systemd 会自动重启当前服务,可能的值包括always(总是重启)、on-success、on-failure、on-abnormal、on-abort、on-watchdog
# TimeoutSec:定义 Systemd 停止当前服务之前等待的秒数
# Environment:指定环境变量