Autostart script at runtime /etc/rc.local


The /etc/rc.local file is common to major Linux distributions.
This file contains BASH commands which will be run after run-level specific commands whenever the system is booted.
In a VPS environment, /etc/rc.local is commonly used to store the hostname <SERVER_HOSTNAME>command (where <SERVER_HOSTNAME> is the intended hostname for the VPS) to ensure that the VPS hostname is not reset when the VPS is rebooted.
                                                                         Method 1                                     
redhat@cloud01:/etc/init.d$ nano rc.local 


  GNU nano 2.2.6                                      File: rc.local                                                                                    


        if [ -x /etc/rc.local ]; then

                [ "$VERBOSE" != no ] && log_begin_msg "Running local boot scripts (/etc/rc.local)"
                /etc/rc.local
                ES=$?
                [ "$VERBOSE" != no ] && log_end_msg $ES
                return $ES
        fi
}

case "$1" in

    start)
        do_start
        ;;
    restart|reload|force-reload)
        echo "Error: argument '$1' not supported" >&2
        exit 3
        ;;
    stop)
        ;;
    *)
        echo "Usage: $0 start|stop" >&2
        exit 3
        ;;
esac
###########################at the end of file >>>>

/root/script/mystartupscript1.sh

/root/script/mystartupscript2.sh  &    #mystartupscript2  & ==the & sends the script to background 
chown wso2:docker /var/run/docker.sock
modprobe aufs
sudo killall dnsmasq


##$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$

                                                        Method 2  #vim   /root/scripts/mystartupscript1.sh
boot=$(date)
echo "the system boot at $boot " >> /var/log/custombootlog.log

#chmod u+x mystartupscript1.sh

#vim /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.
#put your script/command here

chown wso2:docker /var/run/docker.sock
modprobe aufs
sudo killall dnsmasq
/root/script/mystartupscript1.sh
/root/script/mystartupscript2.sh &

exit 0


No comments:

Post a Comment