centeros 8 配置 systemctl()-其他
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
[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重启验证
————————
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
[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重启验证