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:
php -d /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:
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.

#chkconfig 99 10 3

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

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.
arnoldConnect With a Mentor Commented:
You should not assume that php can be found at boot and use a complete path.

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.
Geoff MillikanAuthor Commented:
How do I add the  #chkconfig start stop?
Geoff MillikanAuthor Commented:
AWESOME!! Thanks so much, very helpful.
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.