systemctl开机运行脚本

通过systemctl开机运行特定脚本。

老生常谈,但是为了下次一步到位,节省几秒时间,还是整理下。

  1. /usr/lib/systemd/system 下添加xxx.service
[Unit]
After=network.service

[Service]
Type=forking
ExecStart=xxx             #为服务的具体运行命令
ExecReload=xxx          #为服务的重启命令
ExecStop=xxx             #为服务的停止命令

[Install]
WantedBy=multi-user.target
  1. 给服务文件设置必要的权限,比如754。注意你的目标sh也是有对应执行权限的。
  2. 使能脚本
systemctl daemon-reload
systemctl enable xxx.service
systemctl start xxx.service
  1. 检查是否运行
systemctl is-enabled xxx.service
  1. 其他systemctl 命令
    restart
    disable
    status
    list-units --type=service

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注