systemctl配置详解

[Unit]   书写注释,说明服务作用(可选),服务的依赖

[Service]   核心部分:指定服务开启,关闭,重启分别使用的命令,服务一些环境变量配置文件

[Install]   指定运行级别

 

以sshd服务为例:

[root@web03 /server/tools]# systemctl cat sshd
# /usr/lib/systemd/system/sshd.service
[Unit]
Description=OpenSSH server daemon             #注释 描述
Documentation=man:sshd(8) man:sshd_config(5)  #man帮助
After=network.target sshd-keygen.service      #核心 这个服务在这些服务运行后才能执行(依赖)
Wants=sshd-keygen.service                     #依赖

[Service]
Type=notify                                   #启动类型(simple, forking, oneshot, dbus, notify, idle)
EnvironmentFile=/etc/sysconfig/sshd           #指定环境变量的文件
ExecStart=/usr/sbin/sshd -D $OPTIONS          #服务启动的命令
ExecReload=/bin/kill -HUP $MAINPID            #服务重启的命令
KillMode=process                              #服务关闭方式(建议使用ExecStop)
Restart=on-failure                             
RestartSec=42s

[Install]
WantedBy=multi-user.target                    #指定运行级别

 

posted @ 2021-11-29 21:24  小寒神。  阅读(874)  评论(0编辑  收藏  举报