centeros 8 配置 systemctl
systemctl
-
新建脚本,例如,
/tmp/mytest.sh,设置权限chmod +x /tmp/mytest.sh -
进入目录
/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 -
重新加载systemd配置
systemctl daemon-reload -
添加开机自启动
systemctl enable mytest.service -
reboot重启验证

浙公网安备 33010602011771号