1 修改/etc/rc.local
rc.local脚本是一个ubuntu开机后会自动执行的脚本(重启后),我们可以在该脚本内添加命令行指令
在这里插入图片描述
在exit 0前添加命令即可

2 新建脚本,将脚本添加到启动脚本(推荐,可控,而且非常清楚)
2.1 在/etc/init.d/ 下新建脚本xxx 或者 xxx.sh

#!/bin/bash
 
# command content
 
exit 0
  • 1
  • 2
  • 3
  • 4
  • 5

2.2 设置文件权限

chmod 755 xxx
  • 1

2.3 将脚本添加到启动脚本

update-rc.d xxx defaults 90
  • 1

(移除开机脚本:update-rc.d -f xxx remove)

3 适用于Ubuntu 和 Centos
参考:https://blog.csdn.net/qq_35720307/article/details/87644054

在/etc/init.d编写脚本命令后,比如命名为test,然后直接运行 systemctl enable test 或 systemctl enable test.service

4 查看开机启动项

systemd-analyze blame
  • 1

在这里插入图片描述

点赞(0) 打赏

评论列表 共有 0 条评论

暂无评论

微信小程序

微信扫一扫体验

立即
投稿

微信公众账号

微信扫一扫加关注

发表
评论
返回
顶部