After=network.target sshd-keygen.service Wants=sshd-keygen.service [Service] Type=forking PIDFile=/var/run/sshd.pid EnvironmentFile=/etc/sysconfig/sshd ExecStart=/usr/sbin/sshd $OPTIONS ExecReload=/bin/kill -HUP $MAINPID KillMode=process Restart=on-failure RestartSec=42s [Install] WantedBy=mu...
2.[Service] 区块:启动行为 Service区块定义如何启动当前服务。 2.1 启动命令 许多软件都有自己的环境参数文件,该文件可以用EnvironmentFile字段读取。 EnvironmentFile字段:指定当前服务的环境参数文件。该文件内部的key=value键值对,可以用$key的形式,在当前配置文件中获取。 上面的例子中,sshd 的环境参数文件是/etc/s...
上面的nginx.service文件可以正常启动服务,但无法systemctl reload,只要reload就报错,而且报错时提示kill命令语法错误。kill语法错误显然是因为没有获取到$MAINPID变量的值,而这正是因为systemd在nginx写入PID文件之前先去读取了PID文件,因为没有读取到内容,所以$MAINPID变量为空值。 解决办法是使用ExecStartPost=/usr/bi...
6月 25 10:28:24 Leco.lan nginx[7976]: nginx: configuration file /etc/nginx/nginx.conf test is successful 6月 25 10:28:24 Leco.lan systemd[1]: Started nginx – high performance web server. #重启 $ sudo systemctl restart nginx.service #重载 $ sudo systemctl reload nginx.service #停止...
systemctl reload apache.service# 重载所有修改过的配置文件$ sudo systemctl daemon-reload# 显示某个 Unit 的所有底层参数$ systemctl show httpd.service# 显示某个 Unit 的指定属性的值$ systemctl show -p CPUShares httpd.service# 设置某个 Unit 的指定属性$ sudo systemctl set-property httpd.service ...
[Service] EnvironmentFile=/etc/sysconfig/sshd ExecStart=/usr/sbin/sshd -D $OPTIONS ExecReload=/bin/kill -HUP $MAINPID Type=simple KillMode=process Restart=on-failure RestartSec=42s [Install] WantedBy=multi-user.target 可以看到,配置文件分成几个区块,每个区块包含若干条键值对。
Specifies the commands to run to stop the service started through ExecStart. ExecReload Specifies the commands to run to trigger a configuration reload in the service. Restart Configures whether the service is to be restarted when the service process exits, is stopped, or when a timeout is...
[Service] ExecStart=/bin/bash /usr/sbin/example.sh [Install] WantedBy=multi-user.target 使脚本生效 完成服务脚本编写后,需要执行以下命令重新加载所有的 systemd 服务,否则会找不到 example.service 服务。 sudo systemctl daemon-reload 接着就可以通过systemctl命令来控制服务启停,控制命令语法如下: ...
Copy$ systemctl cat sshd.service [Unit] Description=OpenSSH server daemon Documentation=man:sshd(8) man:sshd_config(5) After=network.target sshd-keygen.service Wants=sshd-keygen.service [Service] EnvironmentFile=/etc/sysconfig/sshd ExecStart=/usr/sbin/sshd -D $OPTIONSExecReload=/bin/kill -HUP...
ExecReload= ExecStop=/usr/local/soft/tomcat/tomcat8/bin/shutdown.sh PrivateTmp=true [Install]WantedBy=multi-user.target 然后给这个tomcat.service 文件chomod +x权限即可!最后在重启下systemctl,命令如下: # systemctl daemon-reload 最后就可以通过systemctl start tomcat启动啦!