Find the answer to your Linux question:
Results 1 to 6 of 6
Hi Everyone, I am wondering how to go about automatically starting programs when my Red Hat (Version Linux distribution starts up. I need to know which file contains startup scripts ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Apr 2003

    Automatically starting programs

    Hi Everyone,

    I am wondering how to go about automatically starting programs when my Red Hat (Version Linux distribution starts up. I need to know which file contains startup scripts and the format of startup commands. This is required because I want to start the Postmaster of PostgreSQL on bootup.

    Also in addition to the above is it possible to set up Red Hat so that a particular program (in this instance PostgreSQL) only starts for a particular login identity?

    Thanks for your assistance.



  2. #2
    Linux Guru
    Join Date
    Oct 2001
    Täby, Sweden
    To run stuff on system startup, you use the SysV init scripts. Check out /etc/rc.d. You can add programs to the rc.local file, but that's quite crude, and PostgreSQL probably has an init script in init.d. You just need to create a link to it in rc3.d or rc5.d, whichever is your default runlevel.

    To run programs when users log in, you must first decide which login manager to use. Do you want them to run when you start GNOME, KDE or when you just log in on a shell? In GNOME, check out the session manager preferences. I don't know about KDE, since I don't use it. In a login shell, add it to the user's .bash_profile script.

  3. #3
    Linux Engineer
    Join Date
    Apr 2003
    In the Redhat distribution a cool program is included. chkconfig that program controlls every default start or stop program located under /etc/init.d and creating and removing symlinks in every runlevel directorys /etc/rc*.d. If your default runlevel is 3 (this you can find out by typing runlevel after bootup) type

    chkconfig --list | grep 3:on to find out which program/services that starts in runlevel 3.

    To enable a program(mysql) in runlevel 3 type:

    chkconfig --level 3 mysql on

    The syntax is:

    chkconfig --level 123456 <program> on|off

    Read the manpage for this program to create your own start and stop scripts. With this program you dont have to go throw difficultis to create symlinks in every runlevel, which can take some time.

    If you dont want to use this create your own start or stopscript and put it under /etc/init.d directory and create symlinks int the runlevel you want your program to start. You can also use /etc/rc.local file that are executed after all other services.



  4. #4
    Linux Guru
    Join Date
    Apr 2003
    London, UK
    use this script for PostGreSQL at boot time, follow the instructions in it:

    #! /bin/sh

    # chkconfig: 2345 98 02
    # description: PostgreSQL RDBMS

    # This is an example of a start/stop script for SysV-style init, such
    # as is used on Linux systems. You should edit some of the variables
    # and maybe the 'echo' commands.
    # Place this file at /etc/init.d/postgresql (or
    # /etc/rc.d/init.d/postgresql) and make symlinks to
    # /etc/rc.d/rc0.d/K02postgresql
    # /etc/rc.d/rc1.d/K02postgresql
    # /etc/rc.d/rc2.d/K02postgresql
    # /etc/rc.d/rc3.d/S98postgresql
    # /etc/rc.d/rc4.d/S98postgresql
    # /etc/rc.d/rc5.d/S98postgresql
    # Or, if you have chkconfig, simply:
    # chkconfig --add postgresql
    # Proper init scripts on Linux systems normally require setting lock
    # and pid files under /var/run as well as reacting to network
    # settings, so you should treat this with care.

    # Original author: Ryan Kirkpatrick <>

    # $Header: /cvsroot/pgsql-server/contrib/start-scripts/linux,v 1.3 2001/07/30 14:52:42 momjian Exp $


    # Installation prefix

    # Data directory

    # Who to run pg_ctl as, should be "postgres".

    # Where to keep a log file


    # Check for echo -n vs echo \c
    if echo '\c' | grep -s c >/dev/null 2>&1 ; then
    ECHO_N="echo -n"
    # The path that is to be used for the script

    # What to use to start up the postmaster

    set -e

    # Only start if we can find pg_ctl.
    test -f $DAEMON || exit 0

    # Parse command line parameters.
    case $1 in
    $ECHO_N "Starting PostgreSQL: "$ECHO_C
    su - $PGUSER -c "$DAEMON start -D '$PGDATA' -s -l $PGLOG"
    echo "ok"
    echo -n "Stopping PostgreSQL: "
    su - $PGUSER -c "$DAEMON stop -D '$PGDATA' -s -m fast"
    echo "ok"
    echo -n "Restarting PostgreSQL: "
    su - $PGUSER -c "$DAEMON restart -D '$PGDATA' -s -m fast"
    echo "ok"
    su - $PGUSER -c "$DAEMON status -D '$PGDATA'"
    # Print help
    echo "Usage: $0 {start|stop|restart|status}" 1>&2
    exit 1

    exit 0


  5. #5
    Just Joined!
    Join Date
    Apr 2003
    For PostgreSQL I would go through the normal SYSV startup scripts.

    To see if you have the SYSV startup for postgres, try typing this from your prompt:

    /etc/rc.d/init.d/postgresql start

    If it starts up, then the SYSV script is in place. You just need to make a link to it from one of the run level areas (/etc/rc.d/rcX.d). Most likely you want to put it in the third run level, like /etc/rc.d/rc3.d/S90postgresql. But make that link to your /etc/rc.d/init.d/postgresql. This is how you do that:

    ln -s /etc/rc.d/init.d/postgresql /etc/rc.d/rc3.d/S90postgresql.

    Everything in your rcX.d dirs that starts with uppercase S will be run during startup (or when you change runlevels). And all the K files will be run with the STOP option to stop (kill) the processes. So you will also need to add a link to shut it down as well (to do it correctly).

    If you just have a script that you write and you want to run it each time there is a quick and dirty way of doing it.
    You can add something like this to your /etc/rc.d/rc.local file. This file is run after all other startup files.

    Somethign like this would work for specifiying users:

    if [ "$UID" = "500" ] ; then

    Just put the correct userid in there. You might also be able to do it by name by using $USER. To check these, from the prompt (logged in as the user), type "echo $UID". Or check the /etc/passwd file for userids, just be careful in there - do not save it.

    Don't forget to chmod 700 [scriptname] (at the very least) to make your script executable.

    Anyway, hope this helps.


  6. #6
    Just Joined!
    Join Date
    May 2003
    UK-Heart of Cheshire
    in redhat there is a gui option called SERVICES under the server setting option. THis can easily be used to configure what starts and what does not

Posting Permissions

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