chenzhao

  • java
  • iOS
  • IT
知识积累
不积跬步无以至千里
  1. 首页
  2. IT
  3. 正文

CentOS7 开启启动自定义脚本

2023年 1月 10日 60点热度 0人点赞 0条评论

服务器 CentOS7 要设置一个开机启动的脚本...
直接使用 vi /etc/rc.d/rc.local 命令,编辑rc.local文件.
但重新启动后发现没有运行相应的脚本....
cat /etc/rc.d/rc.local

#!/bin/bash
# THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES
#
# It is highly advisable to create own systemd services or udev rules
# to run scripts during boot instead of using this file.
#
# In contrast to previous versions due to parallel execution during boot
# this script will NOT be run after all other services.
#
# Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure
# that this script will be executed during boot. 

大致意思是说这个文件是为了兼容而设置的.

如果要使用开始启动 建议使用systemd来建立自己的服务.

如果一定要使用 使用 chmod +x /etc/rc.d/rc.local 来增加权限进行运行.

即然说了不建议使用.我们就不用了.

使用 systemctl 来进行设置自己的服务 其实也非常简单.

1:编辑启动脚本. autostart.sh

注意 此autostart.sh的前三行一定是:

#!/bin/sh
#chkconfig: 2345 80 90
#description:auto_run 

具体什么原因:参考:http://blog.chinaunix.net/uid-20521628-id-365862.html

2:把autostart.sh 放到 /etc/init.d/
3:权限处理 chmod +x autostart.sh

4:运行:systemctl enable autostart.sh
会提示:转发,不用管,/sbin/chkconfig autostart.sh on

4:reboot 启动 脚本成功运行.

5:使用systemctl disable autostart.sh 可以关闭启动.

标签: 暂无
最后更新:2023年 1月 10日

陈昭

IT 程序员

打赏 点赞
< 上一篇
下一篇 >

文章评论

取消回复

COPYRIGHT © 2022 chenzhao. ALL RIGHTS RESERVED.

Theme Kratos Made By Seaton Jiang