systemctl控制服务配置

时间:2022-07-22
本文章向大家介绍systemctl控制服务配置,主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

systemd的使用(/etc/systemd/system)大幅提高了系统服务的运行效率, 其优先级高于([/usr]/lib/systemd/system)

在/etc/systemd/system/目录下创建一个.service文件,该文件如下配置:

[Unit]
Description=high performance web server
After=network.target remote-fs.target
[Service]
Type=simple
WorkingDirectory=/home/ec2-user/root
#程序工作目录
ExecStart=/home/ec2-user/root/server
#程序启动命令
ExecReload=/bin/kill -s -HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
KillMode=process
Restart=on-failure
RestartSec=20s
[Install]
WantedBy=multi-user.target

此后,便可通过systemctl命令对服务进行startrestartstopenabledisable等操作。 刷新systenctl配置命令为:

systemctl daemon-reload