【centos使用系列】centos7下自定义脚本开机自启动

备注

本命令可能很久才会用一次

修改/etc/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.

touch /var/lock/subsys/local
/bin/su - zookeeper -c "/data/zookeeper/bin/zkServer.sh start &" # 启动zookeeper服务
docker ps -a|awk '{print $1}'|xargs docker start #重启docker里面的服务
/bin/su - bbs_abc -c "/data/server/bbs/abc/bin/server.sh restart &"

给/etc/rc.d/rc.local执行权限

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

reboot查看效果

服务已经启动了。