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

Posted on 2011-10-26
Medium Priority
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
  • 4
  • 2
  • 2
LVL 31

Expert Comment

ID: 37030661
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

farzanj earned 600 total points
ID: 37030670
Here is an example script for you.

LVL 31

Expert Comment

ID: 37030687
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.
Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments


Author Comment

ID: 37030690
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

xterm earned 1400 total points
ID: 37030885
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

ID: 37030925
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

ID: 37030940
Sorry, grandchild app should have:

   chkconfig: 2345 57 23

You get the idea though :)

Author Closing Comment

ID: 37124345

Featured Post

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Using libpcap/Jpcap to capture and send packets on Solaris version (10/11) Library used: 1.      Libpcap (http://www.tcpdump.org) Version 1.2 2.      Jpcap(http://netresearch.ics.uci.edu/kfujii/Jpcap/doc/index.html) Version 0.6 Prerequisite: 1.      GCC …
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
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.
Suggested Courses
Course of the Month14 days, 4 hours left to enroll

807 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