centeros 8 配置 systemctl

systemctl

  1. 新建脚本,例如,/tmp/mytest.sh,设置权限chmod +x /tmp/mytest.sh

  2. 进入目录/usr/lib/systemd/system,新建服务,例如mytest.service,编辑为如下形式:

    highlighter- code-theme-dark ini
    [Unit]
    Description=mytest for auto start
    Wants=network-online.target
    
    [Service]
    User=root
    Type=forking
    ExecStart=/usr/bin/bash /tmp/mytest.sh start
    ExecStop=/usr/bin/bash /tmp/mytest.sh stop
    
    [Install]
    WantedBy=multi-user.target
  3. 重新加载systemd配置systemctl daemon-reload

  4. 添加开机自启动systemctl enable mytest.service

  5. reboot重启验证

posted @ 2022-08-07 01:15  小琪子  阅读(93)  评论(0)    收藏  举报