debian系统设置脚本开机时自启动

debian系统设置脚本开机时自启动
这里介绍自己测试使用有效的两种方法,做个记录,备用。

方法一:

1、root用户在 /etc/ 目录下新增 rc.local文件

#!/bin/sh
nohup  /opt/sim/remoteMonitorTool/remoteMonitorTool  &  
exit 0

ps: nohup代码不挂断运行, & 代表后台运行。

2、给文件添加执行权限

chmod +x /etc/rc.local

3、systemd 默认读取 /etc/systemd/system 下的配置文件, 所以还需要在 /etc/systemd/system 目录下创建软链接

ln -s /lib/systemd/system/rc.local.service /etc/systemd/system/ 

4、设置开机自启

systemctl enable rc-local
systemctl start rc-local.service

5、检查状态

systemctl status rc-local.service

返回Active:active信息,则成功。
最后我们就可以在/etc/rc.loacl里,添加开机的自启命令什么的了。记住添加在exit 0之前。

6、注意
更改自启脚本后,需要重新运行一下命令已使其生效。

systemctl enable rc-local
systemctl start rc-local.service

重启电脑后,程序会被root用户调用起来。

方法二:

1、在 /etc/init.d/目录下添加需要执行的.sh脚本,脚本里调用需要开机启动的程序(shell文件格式参考目录下其它文件)
2、给shell脚本test.sh添加执行权限
3、添加自启动命令 update-rc.d test.sh defaults
4、删除自启动的命令 update-rc.d -f test.sh remove

扫描二维码关注公众号,回复: 16788135 查看本文章

猜你喜欢

转载自blog.csdn.net/weixin_38090079/article/details/131665005
今日推荐