Received: from freebie.dcfinc.com ([205.159.99.240]) by postgresql.org (8.11.3/8.11.4) with ESMTP id f97INmn82640 for ; Sun, 7 Oct 2001 14:23:48 -0400 (EDT) (envelope-from chad@eldocomp.com) Received: from paradise (cx74889-a.phnx3.az.home.com [24.1.193.157]) by freebie.dcfinc.com (8.8.7/8.8.3a) with ESMTP id LAA09746; Sun, 7 Oct 2001 11:23:44 -0700 (MST) Message-Id: <4.2.2.20011007111640.00a77ce0@smtp.eldocomp.com> X-Sender: clarson@smtp.eldocomp.com (Unverified) X-Mailer: QUALCOMM Windows Eudora Pro Version 4.2.2 Date: Sun, 07 Oct 2001 11:23:36 -0700 To: Oleg Lebedev , pgsql-admin@postgresql.org From: "Chad R. Larson" Subject: Re: Postmaster startup In-Reply-To: <3BBDFB02.8110693F@waterford.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=====================_477415597==_" X-Archive-Number: 200110/115 X-Sequence-Number: 2361 --=====================_477415597==_ Content-Type: text/plain; charset="us-ascii"; format=flowed At 12:25 PM 10/5/01 -0600, Oleg Lebedev wrote: >I have a script my_script that is run on startup, which has root >permissions. From this script I want to start postgres script, which is >owned by postgres (postgerSQL superuser) and has 's' bit set so that it >executes with postgres priviledges. When I try to run my_script, I get an >error: postmaster: real and effective userids must match what am I doing wrong? On many systems, SUID scripts are considered a security hole. On SysVr4-derived systems, the SUID bit on a script is silently ignored for that reason. If you're half-interested, go look at all the hoops PERL jumps through to run SUID PERL scripts. Anyway, attached is the script I use to start/stop Postgres on a Solaris 2.6 system. Hope it helps. The magic is the "su posgtres -c ..." part. --=====================_477415597==_ Content-Type: text/plain; charset="us-ascii" Content-Disposition: attachment; filename="postgres" #!/sbin/sh # $Id: postgres,v 1.3 2001/08/29 15:55:11 toor Exp $ LINKS='../rc3.d/S05postgres ../rc0.d/K30postgres' # The version of PostgreSQL this is for PGVERSION=7.1.2 PGBASE=/pgsql PGHOME=$PGBASE/$PGVERSION BINDIR=$PGHOME/bin POSTGRES=$BINDIR/postgres INITDB=$BINDIR/initdb PGCTL=$BINDIR/pg_ctl PGUSER=postgres PGLOGFILE=/var/log/pgsql/pgsql.log PATH=$BINDIR:$PATH LD_LIBRARY_PATH=$PGHOME/lib:$LD_LIBRARY_PATH PGLIB=$PGHOME/lib PGDATA=$PGBASE/data export PATH LD_LIBRARY_PATH PGLIB PGDATA ERRMSG1="ERROR: PostgreSQL not installed in $PGHOME!" ERRMSG2="ERROR: 'postgres' program not found in $BINDIR!" ERRMSG3="ERROR: PostgreSQL already running!" ERRMSG4="ERROR: PostgreSQL not started!" ERRMSG5="ERROR: Could not create PostgreSQL data directory for initdb!" OKMSG1="PostgreSQL $PGDATA Initalized." OKMSG2="PostgreSQL $PGVERSION has started." if [ ! -d "$PGHOME" ]; then /usr/bin/logger -p daemon.err $ERRMSG1 exit 1 fi case "$1" in 'start') # If not found if [ ! -f "$POSTGRES" ]; then /usr/bin/logger -p daemon.err $ERRMSG2 exit 1 fi # check to see if PostgreSQL is already running $PGCTL status > /dev/null 2>&1 rtn=$? if [ $rtn -eq 0 ]; then /usr/bin/logger -p daemon.err $ERRMSG3 exit 2 fi # No existing PGDATA, initdb it. if [ ! -d "$PGDATA" ]; then /usr/bin/mkdir -p $PGDATA rtn=$? if [ $rtn -ne 0 ]; then /usr/bin/logger -p daemon.err $ERRMSG5 exit 5 fi /usr/bin/chown postgres:postgres $PGDATA /usr/bin/su $PGUSER -c \ "$INITDB --pgdata=$PGDATA >& /dev/null < /dev/null" rtn=$? if [ $rtn ]; then /usr/bin/logger -p daemon.info $OKMSG1 else /usr/bin/logger -p daemon.err $ERRMSG4 exit 3 fi fi /usr/bin/su $PGUSER -c \ "$PGCTL -w -D $PGDATA -o '-i' -l $PGLOGFILE start" $PGCTL status > /dev/null 2>&1 rtn=$? if [ $rtn -eq 0 ]; then /usr/bin/logger -p daemon.info $OKMSG2 else /usr/bin/logger -p daemon.err $ERRMSG4 exit 4 fi ;; 'stop') /usr/bin/su $PGUSER -c "$PGCTL stop -m smart" /usr/bin/sleep 1 ;; 'links') for LINK in ${LINKS} ; do ln -f ${0} ${LINK} done ;; *) echo "Usage: $0 { start | stop | links}" exit 1 ;; esac exit 0 --=====================_477415597==_ Content-Type: text/plain; charset="us-ascii"; format=flowed -crl -- Chad R. Larson (CRL22) chad@eldocomp.com Eldorado Computing, Inc. 602-604-3100 5353 North 16th Street, Suite 400 Phoenix, Arizona 85016-3228 --=====================_477415597==_--