File: postgresql-startup.in

package info (click to toggle)
postgresql 7.4.7-6sarge6
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 11,168 kB
  • ctags: 27
  • sloc: sh: 1,903; makefile: 337; ansic: 204; perl: 69; sed: 6; tcl: 1
file content (175 lines) | stat: -rw-r--r-- 5,275 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
#! /bin/bash
#include <genscript.warning>
set -e
#
# Initialisation
#
# (This should set up values for POSTGRES_HOME and POSTGRES_DATA, which
# say where the library and database are.  It should also set up DATEFORMAT
# which governs whether the backend sends back dates in European or
# American format, and the logging options.)
# 
# Although Debian policy requires that this file be treated as an
# administrator-alterable conffile, you should NOT treat it as such.
# If you wish to change any values, the proper place to do so is in
# /etc/postgresql/postmaster.conf or /etc/postgresql/postgresql.conf.
#
# To stop postgresql running, use the update-rc.d facility, or file-rc
# if you have that package installed.

check_version () {
	# compare the database format with the format expected by the software
	dbformat=`cat ${PGDATA}/PG_VERSION 2>/dev/null`
	if [ A${dbformat} != A${version} ]
	then
	    if [ -z "${dbformat}" ]
	    then
		echo The database framework has not yet been created. Use
		echo initdb to do this.
	    else
                echo The database is in an older format that cannot be read by
                echo version ${version} of PostgreSQL.
                echo
		if [ -f /var/lib/postgres/dumpall/default_encoding ]
		then
		   echo "The postinstallation script should attempt to upgrade the database"
		   echo "automatically.  If it fails, it must be done by hand."
		else
		   echo Run postgresql-dump to dump the old database and to reload
		   echo it in the new format.
	       fi
	       echo "*** READ /usr/share/doc/postgresql/README.Debian.migration.gz FIRST! ***"
	    fi
	    echo
	    echo The version ${version} postmaster cannot be started until
	    echo this is done.
	    exit 255
	fi
}

obsolete_config () {
	echo "
	******************  Obsolete configuration files  *****************
	
	postmaster.init and pg_options in /etc/postgresql/ are obsolete.

	Please update your configuration files by integrating your site-
	specific changes with the new format in postmaster.conf and
   postgresql.conf and delete or rename the old configuration files.

   PostgreSQL cannot be started until you have done this.

	*******************************************************************
	"
   exit 1
}


# Refuse to proceed if the old config files are still there
if [ -f /etc/postgresql/postmaster.init -o -f /etc/postgresql/pg_options ]
then
	 obsolete_config
	 exit 1
fi

. /etc/postgresql/postmaster.conf

export LANG PGDATESTYLE

if [ -z "${PGDATESTYLE}" ]
then
	PGDATESTYLE=ISO,European
fi

PGDATA="${POSTGRES_DATA:-/var/lib/postgres/data}"
PGLIB=/usr/lib/postgresql
export PGLIB PGDATA
POSTMASTER=${PGLIB}/bin/postmaster
version=%PG_VERSION%		# Note: this is not necessarily the same as the
			# software version.

# Make sure we have a database directory
if [ ! -d ${PGDATA} ]
then
    echo No readable database directory for postgresql
    exit 3
fi

if [ ! -d ${PGDATA}/base ]
then
    echo There is no PostgreSQL database framework in $PGDATA.
    echo Run initdb as the postgres user to create it
    exit 3
fi

# First, check that the database is the right version
check_version

# Make sure that we don't try to start if the executable is missing.
if [ ! -x ${POSTMASTER} ]
then
    echo No postmaster executable for postgresql
    exit 3
fi

OPTIONS="$POSTMASTER_OPTIONS"
if [ -n "$PGPORT" ]
then
	OPTIONS="$OPTIONS -p$PGPORT"
fi

if [ -n "$OPTIONS" ]
then
	OPTIONS="-o '$OPTIONS'"
fi

# If the socket and the pid file exists, and the process with that pid is
# postmaster, then we are already running and abort. Otherwise these files must
# be left from a previous instance (after a crash), so delete them.
SOCKET="/var/run/postgresql/.s.PGSQL.${PGPORT:=5432}"
PIDFILE="$PGDATA/postmaster.pid"
if [ -f "$PIDFILE" ]; then
    pid="`cat $PGDATA/postmaster.pid | head -1`"
fi
if [ "$pid" ] && [ -S "$SOCKET" ] && [ "`ps -o comm h p \"$pid\" 2>/dev/null`" = postmaster ]; then
    echo The postmaster is already running
    exit 1
elif [ "$pid" ] || [ -e "$SOCKET" ]; then
    echo "Removing stale PID file and socket"
    rm -f "$PIDFILE" "$SOCKET"
fi

LOG_OPT="-l ${POSTGRES_LOG:=/var/log/postgresql/postgres.log}"

# set locale that is used by the backend
export LANG=`/usr/lib/postgresql/bin/pg_controldata "$PGDATA" | grep LC_CTYPE | cut -f 2 -d: | awk '{print $1}'`
export LC_ALL=$LANG

# Ready to go: stand clear...
cd ${POSTGRES_HOME}
eval /usr/lib/postgresql/bin/pg_ctl start -s -D ${PGDATA} ${LOG_OPT} ${OPTIONS}

#  Give it a chance to get going
sleep 5

# check if postmaster is really running; yell if not
[ -r $PGDATA/postmaster.pid ] && PMPID=`head -n 1 $PGDATA/postmaster.pid` || true

if [ -z "$PMPID" ] || [ "`ps h -o comm -p $PMPID`" != postmaster ]; then
    echo "ERROR: PostgreSQL postmaster did not start because of an unknown reason." >&2
    cat <<EOF >&2
PostgreSQL's init script (/etc/init.d/postgresql) attempted
to start the postmaster, however, this failed because of an unknown
reason. 

This should not happen and is a serious problem. Please examine the
situation (please take a look at the log files). If you know the
reason why it failed and, then please file a bug report to Debian
(unless the reason is something obvious like a full disk).

Debian PostgreSQL
EOF
    exit 1
fi

exit 0