Thread: Redhat 9.0 Service Shutdown
I start PostgreSQL in the services utility under Redhat 9.0 with no issues. PostgreSQL runs properly but as soon as I log out PostgreSQL shuts down. It seems that I always need to be logged in for it to stay running. I am running: Redhat 9.0 Kernel 2.4.20-20.9 PostgreSQL 7.3.4-3.rh19 I am not sure what else could be helpful. I am fairly new to Linux and PostgreSQL and any pointers would be much appreciated. Regards, Michael
Hi Michael, I am new too. The following has worked for me, though it is quite crude. #1. I created a small script to start and stop PostgreSQL in /etc/init.d. It is named simply "postgres" and the code is as follows: --------------------------- case "$1" in start) su - postgres -c "nohup /usr/local/pgsql/bin/postmaster -D /usr/local/pgsql/data -i > logfile &>2 &";; stop) PID=`head -1 /usr/local/pgsql/data/postmaster.pid | cut -b1-4`; kill -15 $PID;; esac --------------------------- The start line starts postgresql with nohup in the background, so it does not care if anyone particular is logged int or not. The stop line just gets the pid for postmaster and sends it a TERM signal, though it doesn't look that simple. As a newbie, I was having issues using pg_ctl in startup because it needs parameters so I made this as a workaround. New to Linux? Make sure you execute "chmod a+x postgres" on this file after you create it. #2. I wanted postgresql to start in run levels 2, 3, and 5 (single user, multiuser, XWindows) so I created links in the appropriate /etc/rc.d/rc#.d folders (rc2.d, rc3.d, rc5.d). After cd'ing into each folder, I executed the following: for starting postgresql: ln -s /etc/init.d/postgres S92postgres for stopping postgresql: ln -s /etc/init.d/postgres K02postgres This needs to be done in each directory - /etc/rc.d/rc2.d, /etc/rc.d/rc3.d, /etc/rc.d/rc5.d Run level 4 is not used at present, so no need to do it in rc4.d, though no harm either, I suppose. No biggy if you need to change the numeric portion the links, for example, if you already have a K02*, just use K03 or something else that is available. Red Hat had a much slicker startup/shutdown script than mine, but I did not install Postgres on my last install of Linux, instead installing Postgres 7.4 from the postgresql web site, so I had to make my own stuff. Also, I use this exclusively for startup and shutdown - I use pg_ctl for interactive management of PostgreSQL as its much richer than my script. Thanks, Beau -----Original Message----- From: Michael A. Miller [mailto:Michael.Miller@cedillas.com] Sent: Wednesday, December 10, 2003 7:11 PM To: PostgreSQL (General) Subject: [GENERAL] Redhat 9.0 Service Shutdown I start PostgreSQL in the services utility under Redhat 9.0 with no issues. PostgreSQL runs properly but as soon as I log out PostgreSQL shuts down. It seems that I always need to be logged in for it to stay running. I am running: Redhat 9.0 Kernel 2.4.20-20.9 PostgreSQL 7.3.4-3.rh19 I am not sure what else could be helpful. I am fairly new to Linux and PostgreSQL and any pointers would be much appreciated. Regards, Michael ---------------------------(end of broadcast)--------------------------- TIP 9: the planner will ignore your desire to choose an index scan if your joining column's datatypes do not match
In addition to Beau Bummel post, here is a startup script that I find very useful: ----- Begin snip ----- #! /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 <pgsql@rkirkpat.net> # $Header: /cvsroot/pgsql-server/contrib/start-scripts/linux,v 1.3 2001/07/30 14:52:42 momjian Exp $ ## EDIT FROM HERE # Installation prefix prefix=/usr/local/pgsql # Data directory PGDATA="/var/lib/pgsql" # Who to run pg_ctl as, should be "postgres". PGUSER=postgres # Where to keep a log file PGLOG="$PGDATA/pgsql.log" ## STOP EDITING HERE # Check for echo -n vs echo \c if echo '\c' | grep -s c >/dev/null 2>&1 ; then ECHO_N="echo -n" ECHO_C="" else ECHO_N="echo" ECHO_C='\c' fi # The path that is to be used for the script PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin # What to use to start up the postmaster DAEMON="$prefix/bin/pg_ctl" set -e # Only start if we can find pg_ctl. test -f $DAEMON || exit 0 # Parse command line parameters. case $1 in start) $ECHO_N "Starting PostgreSQL: "$ECHO_C su - $PGUSER -c "$DAEMON start -D '$PGDATA' -s -l $PGLOG -o \"-i\"" echo "ok" ;; stop) echo -n "Stopping PostgreSQL: " su - $PGUSER -c "$DAEMON stop -D '$PGDATA' -s -m fast" echo "ok" ;; restart) echo -n "Restarting PostgreSQL: " su - $PGUSER -c "$DAEMON restart -D '$PGDATA' -s -m fast" echo "ok" ;; reload) echo -n "Reloading PostgreSQL configs: " echo "" su - $PGUSER -c "PGDATA=$PGDATA $DAEMON reload" echo "ok" ;; status) su - $PGUSER -c "$DAEMON status -D '$PGDATA'" ;; *) # Print help echo "Usage: $0 {start|stop|restart|status}" 1>&2 exit 1 ;; esac exit 0 ----- End snip ----- Best Regards, Amir Khawaja. Michael A. Miller wrote: > > I start PostgreSQL in the services utility under Redhat 9.0 with no issues. > PostgreSQL runs properly but as soon as I log out PostgreSQL shuts down. It > seems that I always need to be logged in for it to stay running. > > I am running: > Redhat 9.0 Kernel 2.4.20-20.9 > PostgreSQL 7.3.4-3.rh19 > > I am not sure what else could be helpful. > > I am fairly new to Linux and PostgreSQL and any pointers would be much > appreciated. > > Regards, > > Michael > > > > ---------------------------(end of broadcast)--------------------------- > TIP 9: the planner will ignore your desire to choose an index scan if your > joining column's datatypes do not match > -- Amir Khawaja. ---------------------------------- Rules are written for those who lack the ability to truly reason, But for those who can, the rules become nothing more than guidelines, And live their lives governed not by rules but by reason. - James McGuigan