Results 1 to 6 of 6
  1. #1
    Join Date
    Oct 2009
    Posts
    78

    CentOS 5 Startup script..?

    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.

  2. #2
    Join Date
    Apr 2011
    Posts
    235
    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

  3. #3
    Join Date
    Jun 2011
    Location
    Woodbridge, NJ
    Posts
    840
    Here is the proper way to start MySQL automatically on boot with a CentOS 5.x system:

    Code:
    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:

    Code:
    sudo /sbin/chkconfig mysqld on
    To verify, run this command:

    Code:
    chkconfig --list
    Search for the row named 'mysqld'. Check that the mysql service is on for runlevel 3 (you should see 3n 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:

    Code:
    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:

    Code:
    /path/to/script.sh

  4. #4
    Join Date
    Jun 2011
    Location
    Woodbridge, NJ
    Posts
    840
    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:

    Code:
    sudo chkconfig httpd on
    To set sendmail to not start automatically on boot:

    Code:
    sudo chkconfig sendmail off

  5. #5
    Join Date
    Apr 2011
    Posts
    235
    Quote Originally Posted by WhichGunDotCom View Post
    Here is the proper way to start MySQL automatically on boot with a CentOS 5.x system:

    Code:
    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:

    Code:
    sudo /sbin/chkconfig mysqld on
    To verify, run this command:

    Code:
    chkconfig --list
    Search for the row named 'mysqld'. Check that the mysql service is on for runlevel 3 (you should see 3n 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:

    Code:
    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:

    Code:
    /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.

  6. #6
    Quote Originally Posted by vpswing View Post
    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...

Similar Threads

  1. Startup Script
    By Scott_CFR in forum VPS Hosting
    Replies: 2
    Last Post: 08-19-2010, 09:58 AM
  2. Setting a startup process - CentOS
    By csparks in forum Hosting Security and Technology
    Replies: 4
    Last Post: 05-20-2009, 12:35 AM
  3. CentOS - Add perl script to system startup
    By ThatScriptGuy in forum Hosting Security and Technology
    Replies: 11
    Last Post: 09-17-2007, 06:08 PM
  4. Replies: 0
    Last Post: 08-13-2007, 05:14 PM
  5. CentOS 4.4 and Startup Scripts
    By Ryan F in forum Hosting Security and Technology
    Replies: 16
    Last Post: 08-31-2006, 08:15 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •