Monday, February 06, 2012

Autostart/stop your application servers on Linux (RHEL), init.d,rc.d

This is one of these posts, for 'me' as I call them. A log of helpfull tips during work that might prove handy in the future.

So, I am doing lots of Oracle Weblogic configuration on these recent weeks, I needed to make my server instances auto-start and stop along with the operating system, RedHat Enteprise Linux that is. My linux skills are not at the level of Administration, but with a bit of googling and some tips of a colleague of mine - I devised a set of 5-6 steps steps.

1. You need to have shell scripts ready that must follow the init.d convention (that would be accepting start / stop parameters etc.)
./startMyWebLogic start

2. Copy the scripts to /etc/init.d/ folder
3. Check which is the default 'run level' of your Linux server by typing
 cat /etc/inittab 
That would print lots of details but at some point you see a line with the initdefault level, like below:
 id:5:initdefault:
That means thar run level 5 is the default.

4. Browse to the specific run level directory
 cd /etc/rc5.d

5. Create sym links on this folder, pointing to your original script, by following the init.d naming convention, SNameOfscript (for starting the service) and KNameOfScript for shutting down the service. S stands for start and K for kill, the priority is the order (1-99) that you want your scripts to be executed, if it something like 99 you are indicating that you want your scripts to be executed by the system last in the row. This is what I am doing for my server instances, just to make sure that the system has properly initialized every resource is needed
 ln -s /etc/init.d/startMyWebLogic.sh /etc/rc5.d/S99StartMyServer
 ln -s /etc/init.d/startMyWebLogic.sh /etc/rc5.d/K99StopMyServer
That's it!

2 comments:

  1. Nice on Pari.

    Just a few pointers:

    1. By convention we don't use .sh extensions on init scripts. Its fine if you do though

    2. If you add the following lines in the script's header after the sheebang [!/bin/sh]:

    # chkconfig: [runlevels] [startorder] [stoporder]
    # description: My supa script
    # processname: My process

    you can the use chkconfig to handle the correct link creation like so:
    chkconfig --add myscript
    chkconfig myscript on|off


    So in your script you should add the following lines

    # chkconfig: 5 99 99
    # description: Start WebLogic
    # processname: myWebLogic

    and then:
    chkconfig --add startMyWebLogic.sh
    chkconfig startMyWebLogic on

    ReplyDelete
    Replies
    1. Thanks duuuuuuuude! Will update my scripts :)
      :)

      Delete