[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: YANQ (Yet another newbie question...)



Andrew Akins wrote:
  >1) Where do I put programs (daemons) that I want to automatically
  >startup, ie., what is the "Autoexec.bat" file of the unix world? I
  >looked in .bashrc and .bash_profile, which seem to set a lot of
  >enivronment variables, but I don't se if you can put programs in this.
  >
  >In particular, I need to startup my postgres postmaster daemon no matter
  >what account you're logged in as...so I need a system-wide init file.

You need to distinguish between daemons, which serve the whole system, and
user programs.  postmaster serves the whole system, so it is started up
from the rc scripts.  This is how it works:

When Linux boots, the kernel starts and then runs /sbin/init, which is
responsible for everything else.

init reads /etc/inittab and follows the isntructions there.  Usually,
this will mean running `/etc/init.d/rcS' followed by `/etc/init.d/rc 2'
(which is what we need to look at now) and finally gettys are run on the
virtual terminals.

`/etc/init.d/rc 2' looks in /etc/rc2.d for files whose name begins with
S and runs them in order.  Usually, these files are links to files
with friendlier names in /etc/init.d.

You need a file called /etc/init.d/local-postgres, which you should link
to /etc/rc2.d/S99local and to /etc/rc2.d/K99local:

   ln -s /etc/init.d/local-postgres /etc/rc2.d/S99local
   ln -s /etc/init.d/local-postgres /etc/rc2.d/K99local

It should contain something like this, which is part of the initialisation
file from the Debian postgresql package; edit the pathnames to suit your
set-up:

==========================================================================
#! /bin/sh
#

PGDATA=/var/lib/postgresql/data
PGLIB=/usr/lib/postgresql
export PGLIB PGDATA
POSTMASTER=${PGLIB}/bin/postmaster
POSTGRES=${PGLIB}/bin/postgres
OPTIONS="-o -e"    # European date format

case "$1" in
    start)
	su postgres -c "${POSTMASTER} ${OPTIONS}"
        ;;
    stop)
        start-stop-daemon --stop --verbose --exec ${POSTMASTER}
        ;;
    reload|restart)
	start-stop-daemon --stop --verbose --exec ${POSTMASTER}
	su postgres -c "${POSTMASTER} ${OPTIONS}"
	;;
    *)
        echo "Usage: /etc/init.d/local-postgres {start|stop|restart|reload}"
        exit 1
esac

exit 0
==========================================================================




The profile files (.bashrc .bash-profile .profile .xsession .xinitrc and
so on) can be used to set environment variables or to start programs for a
particular user, when that user logs on or starts a bash session or goes
into X.

Unless you are running X, you cannot start interactive programs, because
they will occupy your session and stop you doing anything.  You can
start background programs by adding & after the command.

-- 
Oliver Elphick                                Oliver.Elphick@lfix.co.uk
Isle of Wight                              http://www.lfix.co.uk/oliver

PGP key from public servers; key ID 32B8FAA1




--
TO UNSUBSCRIBE FROM THIS MAILING LIST: e-mail the word "unsubscribe" to
debian-user-request@lists.debian.org . 
Trouble?  e-mail to templin@bucknell.edu .


Reply to: