centos7添加开机启动服务/脚本

一、添加开机启动脚本

1

2

3

4

5

6

7

8

9

10

11

12

13

#!/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.

 

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 +/etc/rc.d/init.d/inotify.sh

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

1

2

3

cd /etc/rc.d/init.d

chkconfig --add inotify.sh

chkconfig inotify.sh

 注意!

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

1

#chkconfig: 345 88 14

 

原文地址:https://www.cnblogs.com/lei0213/p/8595030.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值