From: Chad R. Larson <chad@eldocomp.com>
To: Oleg Lebedev <olebedev@waterford.org>
To: pgsql-admin@postgresql.org
Subject: Re: Postmaster startup
Date: Sun, 07 Oct 2001 11:23:36 -0700
Message-ID: <4.2.2.20011007111640.00a77ce0@smtp.eldocomp.com> (raw)
In-Reply-To: <3BBDFB02.8110693F@waterford.org>
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.
-crl
--
Chad R. Larson (CRL22) chad@eldocomp.com
Eldorado Computing, Inc. 602-604-3100
5353 North 16th Street, Suite 400
Phoenix, Arizona 85016-3228
Attachments:postgres (text/plain, 2.6K) download
#!/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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-admin@postgresql.org
Cc: chad@eldocomp.com, olebedev@waterford.org
Subject: Re: Postmaster startup
In-Reply-To: <4.2.2.20011007111640.00a77ce0@smtp.eldocomp.com>
References: <3BBDFB02.8110693F@waterford.org> <4.2.2.20011007111640.00a77ce0@smtp.eldocomp.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox