[root@lydb ~]# cat /etc/rc.local
#!/bin/sh
#
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don't
# want to do the full Sys V style init stuff.
touch /var/lock/subsys/local
/etc/runonce.d/bin/runonce.sh
exit 0
[root@lydb ~]# ll /etc/runonce.d/bin/runonce.sh
-rwxr-xr-x 1 root root 211 3月 14 22:31 /etc/runonce.d/bin/runonce.sh
[root@lydb ~]# cat /etc/runonce.d/bin/runonce.sh
#!/bin/bash
SCRIPT_PATH="/etc/runonce.d/bin/_runonce.sh"
if [ -f "$SCRIPT_PATH" ]; then
sleep 5s
echo -e "Run $OUTPUT" >> "/etc/runonce.d/scheduler.log"
exec $SCRIPT_PATH & #this doesn't blocks!
fi
[root@lydb ~]# cat /etc/runonce.d/bin/_runonce.sh
#!/bin/bash
CALLBACK_PATH="/etc/runonce.d/run/_callback.sh"
if [ -f "$CALLBACK_PATH" ]; then
CALLBACK_PATH_RAN="/etc/runonce.d/ran/_callback.sh.$(date +%Y%m%dT%H%M%S)"
mv "$CALLBACK_PATH" "$CALLBACK_PATH_RAN"
OUTPUT=`"$CALLBACK_PATH_RAN"`
echo -e "$OUTPUT" > "/etc/runonce.d/callback.log"
else
exit
fi
if [[ -n "$(command -v ntpdate)" ]];then
`ntpdate -s 0.cn.pool.ntp.org`
`ntpdate -s time.google.com`
`ntpdate -s time.windows.com`
fi
[[ -n "$(command -v hwclock)" ]] && `hwclock --systohc`
SELINUX_CONFIG_BACKUP="/etc/selinux/config.backup"
if [ -f "$SELINUX_CONFIG_BACKUP" ]; then
mv -f "/etc/selinux/config.backup" "/etc/selinux/config"
setenforce 1
fi
SYSTEMCTL=$(command -v systemctl)
INITCTL=$(command -v initctl)
CHKCONFIG=$(command -v chkconfig)
if [ -n "${SYSTEMCTL}" ]; then
systemctl disable agent
else
if [ -n "${INITCTL}" ]; then
initctl disable agent
else
if [ -n "${CHKCONFIG}" ]; then
service agent disable
fi
fi
fi
if [ -e "/etc/systemd/system/agent.service" ]; then
rm /etc/systemd/system/agent.service
fi
if [ -e "/etc/init/agent.conf" ]; then
rm /etc/init/agent.conf
fi
if [ -e "/etc/init.d/agent" ]; then
rm /etc/init.d/agent
fi
[[ -n "$(command -v initctl)" ]] && initctl reload-configuration
[[ -n "$(command -v systemctl)" ]] && systemctl daemon-reload
[root@lydb ~]# cd /etc/runonce.d/
[root@lydb runonce.d]# ll
总用量 87864
drwxr-xr-x 2 root root 4096 3月 14 22:31 bin
-rw-r--r-- 1 root root 81095770 6月 25 16:25 callback.log
drwxr-xr-x 2 root root 4096 3月 14 22:32 ran
drwxr-xr-x 2 root root 4096 3月 14 22:32 run
-rw-r--r-- 1 root root 8814490 6月 25 16:28 scheduler.log
[root@lydb runonce.d]#