Ubuntu service开机自启设置

📅 2026/7/8 3:35:06 👁️ 阅读次数 📝 编程学习
Ubuntu service开机自启设置

1、将 这个 test.service文件放到 /etc/systemd/system/目录下

2、执行下面指令开启开机自启

sudo systemctl daemon-reload # 让 systemd 重新读取新 unit sudo systemctl enable test.service # 设置开机自启 sudo systemctl restart test.service # 立刻启动

3、关闭开机自启

sudo systemctl stop test sudo systemctl disable test.service

4、下次开机就不会有这个了

5、sudo systemctl 常见指令

sudo systemctl stop 服务名

命令效果

disable

取消开机自启;不停止当前进程

stop

立刻停止当前进程;不影响开机自启设置

disable --now

同时 disable + stop(取消自启并立刻停掉)

enable

重新设置开机自启(恢复 wants 链接)

restart

重启当前服务(与 enable/disable 无关)