[教程]debian 9 程序随系统启动的做法
1月24日更新• debian9 • rc.local•教程•阅读:2,353次
debian 9 程序随系统启动的做法
我喜欢用nano编辑文件,如果系统没有nano,用下面的命令安装
apt install nano
-
- 创建一个服务:
sudo nano /etc/systemd/system/rc-local.service
- 添加代码在里面:
[Unit] Description=/etc/rc.local Compatibility ConditionPathExists=/etc/rc.local [Service] Type=forking ExecStart=/etc/rc.local start TimeoutSec=0 StandardOutput=tty RemainAfterExit=yes SysVStartPriority=99 [Install] WantedBy=multi-user.target
- 创建文件
/etc/rc.local
:
nano /etc/rc.local
#!/bin/sh -e # # rc.local # # This script is executed at the end of each multiuser runlevel. # Make sure that the script will "exit 0" on success or any other # value on error. # # In order to enable or disable this script just change the execution # bits. # # By default this script does nothing. exit 0
sudo chmod +x /etc/rc.local
- Enable the service:
sudo systemctl enable rc-local
- Start service and check status:
sudo systemctl start rc-local.service sudo systemctl status rc-local.service
- 在exit 0前面添加你的代码到/etc/rc.local中:
比如 bash /root/start.sh ###当然这个start.sh也要给权限chmod +x /root/start.sh
- 创建一个服务: