葡京娱乐开元棋牌_开元棋牌靠谱吗_f1娱乐开元棋牌先锋网 葡京娱乐开元棋牌_开元棋牌靠谱吗_f1娱乐开元棋牌片段及技术文章聚合

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

技术标签: centos7  linux  ubuntu

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

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

编写可以执行脚本如上

bte365假网址:~# cat /usr/local/script/docker-init.sh 
#!/bin/bash
docker start redis
docker start rabbitmq
docker start es5

添加到rc.local

rc.local在/etc目录下

bte365假网址:~# 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 

原文地址:centos7设置开机初始化执行脚本