diff options
| author | Peter Eisentraut <peter_e@gmx.net> | 2000-01-18 00:03:37 +0000 |
|---|---|---|
| committer | Peter Eisentraut <peter_e@gmx.net> | 2000-01-18 00:03:37 +0000 |
| commit | 28125ed5e0b967b71dc9cc686a8e16e1dd9996f8 (patch) | |
| tree | cc64a854f38a797efcd94c8b4eaa14aaed29cd26 /src/bin/ipcclean | |
| parent | 9e0b4634732d089237c5eaecb91ad4b1e943bc0f (diff) | |
| download | postgresql-28125ed5e0b967b71dc9cc686a8e16e1dd9996f8.tar.gz | |
Updated user interfaces on initdb, initlocation, pg_dump, ipcclean to a GNU-compliant'ish state.
Made ipcclean work on Linux.
Diffstat (limited to 'src/bin/ipcclean')
| -rw-r--r-- | src/bin/ipcclean/ipcclean.sh | 102 |
1 files changed, 98 insertions, 4 deletions
diff --git a/src/bin/ipcclean/ipcclean.sh b/src/bin/ipcclean/ipcclean.sh index 64a01e062a..616ec3c964 100644 --- a/src/bin/ipcclean/ipcclean.sh +++ b/src/bin/ipcclean/ipcclean.sh @@ -1,8 +1,102 @@ #!/bin/sh # -# $Header: /cvsroot/pgsql/src/bin/ipcclean/Attic/ipcclean.sh,v 1.2 1998/08/22 05:19:31 momjian Exp $ +# $Header: /cvsroot/pgsql/src/bin/ipcclean/Attic/ipcclean.sh,v 1.3 2000/01/18 00:03:36 petere Exp $ # -PATH=PG_OPT_IPCCLEANPATH_PARAM:$PATH -export PATH -ipcs | egrep '^m .*|^s .*' | egrep "`whoami`|postgres" | \ + +CMDNAME=`basename $0` + +if [ "$1" = '-?' -o "$1" = "--help" ]; then + echo "$CMDNAME cleans up shared memory and semaphores from aborted PostgreSQL backends." + echo + echo "Usage:" + echo " $CMDNAME" + echo + echo "Note: Since the utilities underlying this script are very different" + echo "from platform to platform, chances are that it might not work on" + echo "yours. If that is the case, please write to <bugs@postgresql.org>" + echo "so that your platform can be supported in the future." + exit 0 +fi + +if [ "$USER" = 'root' -o "$LOGNAME" = 'root' ] +then + echo "You cannot run $CMDNAME as root. Please log in (using, e.g., 'su')" + echo "as the (unprivileged) user that owned the server process." + exit 1 +fi + +EffectiveUser=`id -n -u 2>/dev/null || whoami 2>/dev/null` + +#----------------------------------- +# List of platform-specific hacks +# Feel free to add yours here. +#----------------------------------- + +# +# This is based on RedHat 5.2. +# +if [ `uname` = 'Linux' ]; then + ipcs_id= + ipcs_cpid= + ipcs_lpid= + did_anything= + + if ps x | grep -s 'postmaster' >& /dev/null ; then + echo "$CMDNAME: You still have a postmaster running." + exit 1 + fi + + # shared memory + for val in `ipcs -m -p | grep '^[0-9]' | awk '{printf "%s %s\n", $1, $3, $4}'`; do + if [ -z "$ipcs_id" ]; then + ipcs_id=$val + # Note: We can do -n here, because we know the platform. + echo -n "Shared memory $ipcs_id ... " + continue + fi + + ipcs_lpid=$val + + # Don't do anything if process still running. + # (This check is conceptually phony, but it's + # useful anyway in practice.) + ps hj$ipcs_pid >& /dev/null + if [ $? -eq 0 ]; then + echo "skipped. Process still exists (pid $ipcs_pid)." + else + # try remove + ipcrm shm $ipcs_id + if [ $? -eq 0 ]; then + did_anything=t + else + exit + fi + fi + ipcs_id= + ipcs_cpid= + ipcs_lpid= + done + + # semaphores + for val in `ipcs -s -c | grep '^[0-9]' | awk '{printf "%s\n", $1}'`; do + echo -n "Semaphore $val ... " + # try remove + ipcrm sem $val + if [ $? -eq 0 ]; then + did_anything=t + else + exit + fi + done + + [ -z "$did_anything" ] && echo "$CMDNAME: nothing removed" && exit 1 + exit 0 +fi # end Linux + + +# This is the original implementation. It seems to work +# on FreeBSD, SunOS/Solaris, HP-UX, IRIX, and probably +# some others. + +ipcs | egrep '^m .*|^s .*' | egrep "$EffectiveUser" | \ awk '{printf "ipcrm -%s %s\n", $1, $2}' '-' | sh |
