Find the answer to your Linux question:
Results 1 to 7 of 7
Hi All, I have written an init script and placed it in /etc/init.d/ directory. What I would like to know is, will the script run automatically or we need to ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Sep 2010

    Init scripts in /etc/init.d

    Hi All,

    I have written an init script and placed it in /etc/init.d/ directory.

    What I would like to know is, will the script run automatically or
    we need to install the script using "install_initd" command.

    If I have to invoke this command manullay, what will be the best place to do this ? Can I add this to "/etc/init.d/rcS" file.

    Thanks in advance,

  2. #2
    RDU is offline
    Just Joined!
    Join Date
    Aug 2010
    This is distro dependant. But simply placing the script in the init.d directory do nothing. You can use the 'service' command to start/stop the service.
    e.g. # service xxxx command

    If you put some ad-hoc comment in your script, you can use chkconfig to automaticaly link start and stop to various run-level
    e.g. # chkconfig --level 345 xxxxx on

    You should have this in your script :
    # chkconfig: 345 40 60

    345 = runlevels ; 40 and 60 are the order for start and stop

    This work on red-hat/centos/mandriva. Don't know for other.
    Take a look at :
    # man chkconfig

  3. #3
    Linux Newbie nplusplus's Avatar
    Join Date
    Apr 2010
    Charlotte, NC, USA
    Debian-based distros have similar functionality to Redhat-based distros, but the commands are different. Regardless, on most distros, you should be able to type something like
    man -k init
    to begin to find information on what you are looking for.

  4. $spacer_open
  5. #4
    Just Joined!
    Join Date
    Jun 2006
    In Ubuntu one might just use System/Preferences/Startup Applications.
    It's good for configuration scripts despite its GUI looks.

  6. #5
    pdk is offline
    Just Joined!
    Join Date
    Aug 2008
    /etc/init.d is the place to put startup and shut down scripts.
    When linux starts up it goes thrpugh init stages. The startup 'commands' are stored in the /etc/rc (*).d directories. Check out the files already there.
    The ones starting with 'K' are kill commands an the ones starting with 'S' are start commands.
    /etc/rc2.d is probably where you should create a file S090mytask
    /etc/init.d allows you to have only one copy of a task and be able to start it from any state.

  7. #6
    scm is offline
    Linux Engineer
    Join Date
    Feb 2005
    If you look in, say rc3.d, you'll probably find the files in there are either symlinks to init.d or hard links to the init.d files. You just need equivalent K and S links to your script in the relevant rcN.d directories.

  8. #7
    asg is offline
    Just Joined!
    Join Date
    Feb 2009
    The various bits of advice so far will show you how to get the script executed but a word of warning - unless you are absolutely certain about your script NEVER place at a run level below or equal to your system default level i.e. if you currently boot to level 2 by default DO NOT try your script out at level 1 or 2 - you may find you never get a prompt ! With a deault level of 2, place the script at level 3 and once you have a root shell type "init 3".

Posting Permissions

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