ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

编写systemd Unit文件

2022-01-09 01:02:26  阅读:192  来源: 互联网

标签:systemd target systemctl web1 test 编写 root Unit


熟悉systemctl常用命令

[root@web1 ~]# systemctl                             #列出所有启动的服务
[root@web1 ~]# systemctl status   <服务名称>            #查看服务状态
[root@web1 ~]# systemctl start     <服务名称>        #启动服务状态
[root@web1 ~]# systemctl stop      <服务名称>        #关闭服务状态
[root@web1 ~]# systemctl restart  <服务名称>        #重启服务状态
[root@web1 ~]# systemctl enable  <服务名称>            #设置开机自启
[root@web1 ~]# systemctl enable --now  <服务名称>    #设置开机自启并启动
[root@web1 ~]# systemctl disable  <服务名称>        #禁止开机自启
[root@web1 ~]# systemctl enable  <服务名称>            #设置开机自启
[root@web1 ~]# systemctl is-active <服务名称>        #查看是否激活
[root@web1 ~]# systemctl is-enabled  <服务名称>        #查看是否开启自启
[root@web1 ~]# systemctl reboot                    #重启计算机
[root@web1 ~]# systemctl poweroff                     #关闭计算机

使用systemd管理shell脚本

编写shell脚本

vim /root/test.sh

#!/bin/bash
while : 
do
    echo NB
    echo DACHUI
done

chmod +x /root/test.sh

编写Unit文件

cp /usr/lib/systemd/system/{crond.service,test.service}
vim /usr/lib/systemd/system/test.service

[Unit]
Description=my test script
After=time-sync.target
[Service]
ExecStart=/root/test.sh
ExecReload=/bin/kill -HUP $MAINPID
KillMode=process
[Install]
WantedBy=multi-user.target

使用systemd管理Nginx服务

vim /usr/lib/systemd/system/nginx.service

[Unit]
Description=The Nginx HTTP Server        #描述信息
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
#仅启动一个主进程的服务为simple,需要启动若干子进程的服务为forking
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/bin/kill -s QUIT ${MAINPID}
[Install]
WantedBy=multi-user.target

标签:systemd,target,systemctl,web1,test,编写,root,Unit
来源: https://www.cnblogs.com/barry-zou/p/15780106.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有