|
1 |
| -#! /bin/sh |
| 1 | +#!/bin/sh |
2 | 2 | #
|
3 | 3 | # postgres.init Start postgres back end system.
|
4 | 4 | #
|
5 |
| -# Author: Thomas Lockhart <Thomas.Lockhart@jpl.nasa.gov> |
6 |
| -# based on news startup by David Myers |
| 5 | +# Author: Thomas Lockhart <lockhart@alumni.caltech.edu> |
| 6 | +# modified from other startup files in the RedHat Linux distribution |
7 | 7 | #
|
8 |
| -# Written for RedHat Linux but should apply to other Linux distributions. |
9 |
| -# |
10 |
| -# To be installed as /etc/rc.d/init.d/postgres.init |
11 |
| -# Softlink into rc5.d to bring up with multiuser and networking: |
12 |
| -# cd /etc/rc.d/rc5.d; ln -s ../init.d/postgres.init S98postgres |
13 |
| -# |
14 |
| -# Assumptions: |
15 |
| -# - the postgres user is named "postgres" |
16 |
| -# - the postgres user is running csh/tcsh |
| 8 | +# This version can log backend output through syslog using the local5 facility. |
| 9 | +# To enable this, edit /etc/syslog.conf to include a line similar to: |
| 10 | +# local5.* /var/log/postgres |
| 11 | +# and then set USE_SYSLOG to "yes" below |
17 | 12 | #
|
| 13 | +#PGBIN="/opt/postgres/current/bin" # not used |
| 14 | +PGACCOUNT="postgres" # the postgres account (you called it something else?) |
| 15 | +POSTMASTER="postmaster" # this probably won't change |
| 16 | + |
| 17 | +USE_SYSLOG="yes" # "yes" to enable syslog, "no" to go to /tmp/postgres.log |
| 18 | +FACILITY="local5" # can assign local0-local7 as the facility for logging |
| 19 | +PGLOGFILE="/tmp/postgres.log" # only used if syslog is disabled |
| 20 | + |
| 21 | +PGOPTS="-B 256" |
| 22 | +#PGOPTS="-i -B 256" # -i to enable TCP/IP rather than Unix socket |
18 | 23 |
|
19 | 24 | # Source function library.
|
20 | 25 | . /etc/rc.d/init.d/functions
|
|
29 | 34 | exit 0
|
30 | 35 | fi
|
31 | 36 |
|
32 |
| -[ -f /opt/postgres/current/bin/postmaster ] || exit 0 |
| 37 | +#[ -f ${PGBIN}/${POSTMASTER} ] || exit 0 |
33 | 38 |
|
34 | 39 | # See how we were called.
|
35 | 40 | case "$1" in
|
36 | 41 | start)
|
37 |
| - echo -n "Starting postgres service: " |
38 |
| -# force full login to get path names and environment variables |
39 |
| -# postgres runs tcsh so use proper syntax in redirection |
40 |
| -# change this line if the postgres superuser account is not "postgres" |
41 |
| -# change this line if another shell syntax is necessary |
42 |
| -# su - postgres -c 'postmaster -S' > /dev/null& |
43 |
| - su - postgres -c 'postmaster >>&! /tmp/postmaster.log&' > /dev/null& |
| 42 | + if [ -f ${PGLOGFILE} ] |
| 43 | + then |
| 44 | + mv ${PGLOGFILE} ${PGLOGFILE}.old |
| 45 | + fi |
| 46 | + echo -n "Starting postgres: " |
| 47 | +# force full login to get path names |
| 48 | +# my postgres runs tcsh so use proper syntax in redirection... |
| 49 | + if [ ${USE_SYSLOG} = "yes" ]; then |
| 50 | + su - ${PGACCOUNT} -c "(${POSTMASTER} ${PGOPTS} |& logger -p ${FACILITY}.notice) &" > /dev/null& |
| 51 | + else |
| 52 | + su - ${PGACCOUNT} -c "${POSTMASTER} ${PGOPTS} >>&! ${PGLOGFILE} &" > /dev/null& |
| 53 | + fi |
44 | 54 | sleep 5
|
45 |
| - pid=`pidof postmaster` |
46 |
| - echo -n "postmaster [$pid]" |
47 |
| -# touch /var/lock/subsys/postmaster |
| 55 | + pid=`pidof ${POSTMASTER}` |
| 56 | + echo -n "${POSTMASTER} [$pid]" |
| 57 | +# touch /var/lock/subsys/${POSTMASTER} |
48 | 58 | echo
|
49 | 59 | ;;
|
50 | 60 | stop)
|
51 |
| - echo -n "Stopping postgres service: " |
52 |
| - pid=`pidof postmaster` |
| 61 | + echo -n "Stopping postgres: " |
| 62 | + pid=`pidof ${POSTMASTER}` |
53 | 63 | if [ "$pid" != "" ] ; then
|
54 |
| - echo -n "postmaster [$pid]" |
| 64 | + echo -n "${POSTMASTER} [$pid]" |
55 | 65 | kill -TERM $pid
|
56 | 66 | sleep 1
|
57 | 67 | fi
|
58 | 68 | echo
|
59 | 69 | ;;
|
60 | 70 | *)
|
61 |
| - echo "Usage: postgres.init {start|stop}" |
| 71 | + echo "Usage: $0 {start|stop}" |
62 | 72 | exit 1
|
63 | 73 | esac
|
64 | 74 |
|
|
0 commit comments