systemd

发布时间 2023-06-07 00:41:37作者: 不笔记不学习

systemd脚本

像mycat这样的 用命令start的 就需要设置为type=forking Execstart Execstop ......



    [root@localhost system]# cat mycat.service 

    [Unit]

    Description=/etc/systemd/system/mycat.service

    After=network.target


    [Service]

    Type=forking

    ExecStart=/home/mycat/bin/mycat start

    ExecStop=/home/mycat/bin/mycat stop

    ExecReload=/home/mycat/bin/mycat restart


    [Install]

    WantedBy=multi-user.target

haproxy这样 是用命令一条启动 杀死要kill进程,则直接就是一条Execstart就行了


    [Unit]

    Description=/etc/systemd/system/haproxy.service

    After=network.target


    [Service]

    #Type=forking

    ExecStart=/home/haproxy/haproxy-1.7.8/haproxy -f /home/haproxy/haproxy-1.7.8/conf/haproxy.cfg



    [Install]

    WantedBy=multi-user.target

yum安装nginx生成的sysemd脚本,也是命令生成的,所以也用execstart,execstop,execreload

[Unit]
Description=nginx - high performance web server
Documentation=http://nginx.org/en/docs/
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStartPre=/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecReload= /usr/local/nginx/sbin/nginx -s reload
ExecStop= /usr/local/nginx/sbin/nginx -s stop
PrivateTmp=true
[Install]
WantedBy=multi-user.target