[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 #指定運行級別