正好有此操作需求,特地找了一下,还算靠谱。

摘录于:https://www.cnblogs.com/lei0213/p/8595030.html

 

一、添加开机启动脚本
1
2
3
4
5
6
7
8
9
10
11
12
13
#!/bin/bash
# THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES
#chkconfig: 345 88 14
#
# 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.
touch /var/lock/subsys/local<br>#添加开机启动inotify.sh脚本<br>/root/inotify.sh

 

方法一

注意、服务也可以使用下面方法设置开机启动,如追加rc.local文件追加/usr/bin/rsync –daemon就是开启启动rsync服务

1、首先,脚本具有可执行权限

1
chmod 755 inotify.sh

2、然后将脚本存放的绝对路径+脚本全名追加到/etc/rc.d/rc.local文件最后

1
/root/inotify.sh

3、在centos7中,/etc/rc.d/rc.local的权限被降低了,所以需要执行如下命令赋予其可执行权限

1
chmod +x /etc/rc.d/rc.local

 

 

方法二

1、将脚本移动到/etc/rc.d/init.d目录下

1
mv /opt/script/inotify.sh /etc/rc.d/init.d

2、增加脚本的可执行权限

1
chmod +x /etc/rc.d/init.d/inotify.sh

3、添加脚本到开机自动启动项目中

1
2
3
cd /etc/rc.d/init.d
chkconfig --add inotify.sh
chkconfig inotify.sh on

注意!

你直接把你的平时写的加的脚本这样chkconfig –add 肯定是要报service inotify.sh does not support chkconfig 错误的,不过你只需要在#!/bin/bash下面加上如下内容就行。

1
#chkconfig: 345 88 14

 


0 条评论

发表评论

邮箱地址不会被公开。 必填项已用*标注