centos7设置开机初始化执行脚本

由于每次启动都要执行网络重启,所以才有了本篇文章。

centos7

编写脚本,添加可执行的权限

/usr/local/script/sh_network.sh

#!/bin/bash
service network restart

执行如下命令将/etc/rc.d/rc.local文标记为可执行文件

执行如下命令将/etc/rc.d/rc.local文标记为可执行文件

打开/etc/rc.d/rc.local文件,在最后面添加如下脚本

/usr/local/script/sh_network.sh

这样sh_network.sh这个脚本在开机的时候就会被执行了。

ubuntu16.04

编写可以执行脚本如上

root@dev:~# cat /usr/local/script/docker-init.sh 
#!/bin/bash
docker start redis
docker start rabbitmq
docker start es5

添加到rc.local

rc.local在/etc目录下

root@dev:~# cat /etc/rc.local 
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.

#log
exec 2> /tmp/rc.local.log  # send stderr from rc.local to a log file  
exec 1>&2                  # send stdout to the same log file  
set -x                     # tell sh to display commands before execution 

sh /usr/local/script/docker-init.sh

exit 0

添加日志

#log
exec 2> /tmp/rc.local.log  # send stderr from rc.local to a log file  
exec 1>&2                  # send stdout to the same log file  
set -x                     # tell sh to display commands before execution 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值