How to run a script at start up which loads a MySQL database?

My CentOS5 server boots to runlevel 3 so do I need to do anything other than:

1. Create script called /etc/rc.d/init.d/php_mysql_memory_table_maxmind that looks like this:
#!/bin/bash
php -d extension=mysqli.so /home/t1shopper/www/api/internal/maxmind/maxmind.php

Open in new window

2. Create symbolic link in /etc/rc.d/rc3.d called S99php_mysql_memory_table_maxmind linking to above file.

Now whenever the server reboots (or changes runlevel back to 3), it will run my script, right?

Note to self:
http://superuser.com/questions/126106/how-to-execute-a-shell-script-on-startup
Geoff MillikanAsked:
Who is Participating?
 
arnoldConnect With a Mentor Commented:
Look at any other script within /etc/init.d
The third item deals with run levels.

#!/bin/sh
#chkconfig 99 10 3

case $1 in
        start)
         /usr/bin/php .....
        ;;
        stop)
         # nothing to be done
         ;;
         *) #default
            echo "Usage: $0 (start|stop)"
         ;;
esac

Once you save in in /etc/init.d/
 You can use chkconfig to add this script
chkconfig --add scriptname
chkconfig --enable scriptname
chkconfig scriptname on.
0
 
arnoldConnect With a Mentor Commented:
Yes.
You should not assume that php can be found at boot and use a complete path.
/usr/bin/php

When the system will boot the script will run as you specify.

The script should include #chkconfig start stop
Presumably you do not want this script to run at other times.
Enclosing using the case to see whether a start, stop, or directive is being passed.
0
 
Geoff MillikanAuthor Commented:
How do I add the  #chkconfig start stop?
0
 
Geoff MillikanAuthor Commented:
AWESOME!! Thanks so much, very helpful.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.