Hi,
I'm not that good at CentOS and the last time I attempted a startup script I broke my VPS for a good few hours, so I thought this could be a good site to ask for some advice.
I would like to create a startup script that does the following:
- Starts MySQL Service
- Goes to a directory and runs a SH script.
Could anyone help me out with creating a startup script properly?
Thanks.
vpswing
08-05-2011, 12:35 PM
Hi,
You can edit the /etc/rc.local file.
A default one (mine) looks like this:
----------
#!/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
------------------------------
To start mysql automatically, just add on a new line:
/etc/init.d/mysqld start
OR
/sbin/service mysqld start
To run your custom script ONLY after mysql has started, you can use the && operand, e.g.
/sbin/service mysqld start && /path/to/customshellscript.sh
VectorVPS
08-06-2011, 01:50 AM
Here is the proper way to start MySQL automatically on boot with a CentOS 5.x system:
sudo chkconfig mysqld on
If you get a 'command not found' error, your path does not include /sbin (which is where the chkconfig command lives). You will need to either add /sbin to your path, or run this command:
sudo /sbin/chkconfig mysqld on
To verify, run this command:
chkconfig --list
Search for the row named 'mysqld'. Check that the mysql service is on for runlevel 3 (you should see 3:on in this row).
As before, if /sbin is not in your path, simply run "/sbin/chkconfig --list".
You can set other services to start (or not to start) on boot. For example, to set Apache to start at boot:
sudo chkconfig httpd on
To automatically run the bash script on boot, vpswing's instructions are correct. Edit /etc/rc.local and add a line at the end pointing towards the script:
/path/to/script.sh
VectorVPS
08-06-2011, 01:57 AM
Also, you can use the chkconfig command to set other services to start (or not to start) on boot.
To set Apache to start automatically on boot:
sudo chkconfig httpd on
To set sendmail to not start automatically on boot:
sudo chkconfig sendmail off
vpswing
08-06-2011, 11:46 AM
Here is the proper way to start MySQL automatically on boot with a CentOS 5.x system:
sudo chkconfig mysqld on
If you get a 'command not found' error, your path does not include /sbin (which is where the chkconfig command lives). You will need to either add /sbin to your path, or run this command:
sudo /sbin/chkconfig mysqld on
To verify, run this command:
chkconfig --list
Search for the row named 'mysqld'. Check that the mysql service is on for runlevel 3 (you should see 3:on in this row).
As before, if /sbin is not in your path, simply run "/sbin/chkconfig --list".
You can set other services to start (or not to start) on boot. For example, to set Apache to start at boot:
sudo chkconfig httpd on
To automatically run the bash script on boot, vpswing's instructions are correct. Edit /etc/rc.local and add a line at the end pointing towards the script:
/path/to/script.sh
Thanks for that! I knew CentOS had something like Ubuntu's update-rc.d command - was too lazy to look it up and used the "rc.local" shortcut.
nujum
08-22-2011, 11:42 AM
Hi,
You can edit the /etc/rc.local file.
A default one (mine) looks like this:
----------
#!/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
------------------------------
To start mysql automatically, just add on a new line:
/etc/init.d/mysqld start
OR
/sbin/service mysqld start
To run your custom script ONLY after mysql has started, you can use the && operand, e.g.
/sbin/service mysqld start && /path/to/customshellscript.sh
thx u help me that example for auto start my openVPN after boot... :D