Setting up auto-startup when OS starts up or reboot on Linux

Posted on 2011-10-26
Last Modified: 2012-05-12

Would like to configure auto-startup on few process on linux OS. Could you suggest detailed steps please

Scenario is, I have few applications running on Linux which has dependencies between them (Parent, child, grand child). So when OS reboots/starts....would like to
1. start  parent app first
2 wait for parent to be running, then start child app
3 wait for child to be running, then start grand-child app.

Also similar for graceful shutdown

Thanks in advance
Question by:enthuguy
    LVL 31

    Expert Comment

    What is your Linux distro?

    You have to create a /etc/rc.d kind of script.  This would start it in the order you mentioned.  Will also shut in the correct order.
    LVL 31

    Assisted Solution

    Here is an example script for you.
    LVL 31

    Expert Comment

    Once you create the script and run it successfully as per your wishes, you will have to add a symlink of it in the folder of your run level like rc3.d or rc5.d.  This is done with a simple command but that command is different with different distributions.

    Author Comment

    Hi Farzanj, Thanks for your quick comment.

    To be precise...I run Oracle Enterprise Linux 5.x

    Above sample script would work for me?
    LVL 19

    Accepted Solution

    Create /etc/init.d/parentname
    Create /etc/init.d/childname
    Create /etc/init.d/grandchildname

    Each of these should be set up to take the arguments "stop" or "start".

    So /etc/init.d/parentname will start your parent app
    And /etc/init.d/childname will start your child app
    And /etc/init.d/grandchildname will start your grandchild app

    If you don't have one created, simply go into /etc/init.d, do "ls -l" and find one of the smaller sized ones and copy/clone it for your own use.  They are quite simple.

    Now that you have these created, you need to customize the order that they start up.

    You will see each file in there has a line referencing "chkconfig" that looks something like this:

      chkconfig: 2345 55 25

    The first argument are the run levels in which your script will run - you probably don't need to change this from 2345.

    The 2nd and 3rd arguments are the startup and shutdown order respectively.

    For your parent app you could put:

      chkconfig: 2345 55 25

    And your child app:

      chkconfig: 2345 56 24

    And grandchild app:

      chkconfig: 2345 56 23

    This would start your parent app and then the child app and then your grandchild app, and then when you shut down the system it will terminate them in reverse order

    After you've modified these, do:

      chkconfig --add parent
      chkconfig --add child
      chkconfig --add grandchild

    Then when you do "chkconfig --list parent" (or the other two) it should say:

      parent            0:off   1:off   2:on    3:on    4:on    5:on    6:off

    BTW, the system startup doesn't wait per se for applications to startup, it simply waits for the previous startup scripts to exit.  So if you want to be sure that one thing has started up fully prior to launching the next, you will want to not launch the parent into the background (aka, do not use the "&" character behind the command that starts it) or perhaps insert some sleep X lines to slow it down if need be.  Keep in mind though, that you could delay your system boot up if these processes are slow to start.
    LVL 31

    Expert Comment

    It should work for you.  If you include all the three processes in the same startup script, you will have the control over the start and end order of processes.
    LVL 19

    Expert Comment

    Sorry, grandchild app should have:

       chkconfig: 2345 57 23

    You get the idea though :)

    Author Closing Comment


    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    I have been running these systems for a few years now and I am just very happy with them.   I just wanted to share the manual that I have created for upgrades and other things.  Oooh yes! FreeBSD makes me happy (as a server), no maintenance and I al…
    Introduction Regular patching is part of a system administrator's tasks. However, many patches require that the system be in single-user mode before they can be installed. A cluster patch in particular can take quite a while to apply if the machine…
    Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
    This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

    745 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now