| 1 |
#! /bin/sh |
| 2 |
|
| 3 |
# chkconfig: 2345 98 02 |
| 4 |
# description: PostgreSQL RDBMS |
| 5 |
|
| 6 |
# This is an example of a start/stop script for SysV-style init, such |
| 7 |
# as is used on Linux systems. You should edit some of the variables |
| 8 |
# and maybe the 'echo' commands. |
| 9 |
# |
| 10 |
# Place this file at /etc/init.d/postgresql (or |
| 11 |
# /etc/rc.d/init.d/postgresql) and make symlinks to |
| 12 |
# /etc/rc.d/rc0.d/K02postgresql |
| 13 |
# /etc/rc.d/rc1.d/K02postgresql |
| 14 |
# /etc/rc.d/rc2.d/K02postgresql |
| 15 |
# /etc/rc.d/rc3.d/S98postgresql |
| 16 |
# /etc/rc.d/rc4.d/S98postgresql |
| 17 |
# /etc/rc.d/rc5.d/S98postgresql |
| 18 |
# Or, if you have chkconfig, simply: |
| 19 |
# chkconfig --add postgresql |
| 20 |
# |
| 21 |
# Proper init scripts on Linux systems normally require setting lock |
| 22 |
# and pid files under /var/run as well as reacting to network |
| 23 |
# settings, so you should treat this with care. |
| 24 |
|
| 25 |
# Original author: Ryan Kirkpatrick <[email protected]> |
| 26 |
|
| 27 |
# contrib/start-scripts/linux |
| 28 |
|
| 29 |
## EDIT FROM HERE |
| 30 |
|
| 31 |
# Installation prefix |
| 32 |
prefix=/usr/local/pgsql |
| 33 |
|
| 34 |
# Data directory |
| 35 |
PGDATA="/usr/local/pgsql/data" |
| 36 |
|
| 37 |
# Who to run postgres as, usually "postgres". (NOT "root") |
| 38 |
PGUSER=postgres |
| 39 |
|
| 40 |
# Where to keep a log file |
| 41 |
PGLOG="$PGDATA/serverlog" |
| 42 |
|
| 43 |
# It's often a good idea to protect the postmaster from being killed by the |
| 44 |
# OOM killer (which will tend to preferentially kill the postmaster because |
| 45 |
# of the way it accounts for shared memory). To do that, uncomment these |
| 46 |
# three lines: |
| 47 |
#PG_OOM_ADJUST_FILE=/proc/self/oom_score_adj |
| 48 |
#PG_MASTER_OOM_SCORE_ADJ=-1000 |
| 49 |
#PG_CHILD_OOM_SCORE_ADJ=0 |
| 50 |
# Older Linux kernels may not have /proc/self/oom_score_adj, but instead |
| 51 |
# /proc/self/oom_adj, which works similarly except for having a different |
| 52 |
# range of scores. For such a system, uncomment these three lines instead: |
| 53 |
#PG_OOM_ADJUST_FILE=/proc/self/oom_adj |
| 54 |
#PG_MASTER_OOM_SCORE_ADJ=-17 |
| 55 |
#PG_CHILD_OOM_SCORE_ADJ=0 |
| 56 |
|
| 57 |
## STOP EDITING HERE |
| 58 |
|
| 59 |
# The path that is to be used for the script |
| 60 |
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin |
| 61 |
|
| 62 |
# What to use to start up postgres. (If you want the script to wait |
| 63 |
# until the server has started, you could use "pg_ctl start" here.) |
| 64 |
DAEMON="$prefix/bin/postgres" |
| 65 |
|
| 66 |
# What to use to shut down postgres |
| 67 |
PGCTL="$prefix/bin/pg_ctl" |
| 68 |
|
| 69 |
set -e |
| 70 |
|
| 71 |
# Only start if we can find postgres. |
| 72 |
test -x $DAEMON || |
| 73 |
{ |
| 74 |
echo "$DAEMON not found" |
| 75 |
if [ "$1" = "stop" ] |
| 76 |
then exit 0 |
| 77 |
else exit 5 |
| 78 |
fi |
| 79 |
} |
| 80 |
|
| 81 |
# If we want to tell child processes to adjust their OOM scores, set up the |
| 82 |
# necessary environment variables. Can't just export them through the "su". |
| 83 |
if [ -e "$PG_OOM_ADJUST_FILE" -a -n "$PG_CHILD_OOM_SCORE_ADJ" ] |
| 84 |
then |
| 85 |
DAEMON_ENV="PG_OOM_ADJUST_FILE=$PG_OOM_ADJUST_FILE PG_OOM_ADJUST_VALUE=$PG_CHILD_OOM_SCORE_ADJ" |
| 86 |
fi |
| 87 |
|
| 88 |
|
| 89 |
# Parse command line parameters. |
| 90 |
case $1 in |
| 91 |
start) |
| 92 |
echo -n "Starting PostgreSQL: " |
| 93 |
test -e "$PG_OOM_ADJUST_FILE" && echo "$PG_MASTER_OOM_SCORE_ADJ" > "$PG_OOM_ADJUST_FILE" |
| 94 |
su - $PGUSER -c "$DAEMON_ENV $DAEMON -D '$PGDATA' >>$PGLOG 2>&1 &" |
| 95 |
echo "ok" |
| 96 |
;; |
| 97 |
stop) |
| 98 |
echo -n "Stopping PostgreSQL: " |
| 99 |
su - $PGUSER -c "$PGCTL stop -D '$PGDATA' -s" |
| 100 |
echo "ok" |
| 101 |
;; |
| 102 |
restart) |
| 103 |
echo -n "Restarting PostgreSQL: " |
| 104 |
su - $PGUSER -c "$PGCTL stop -D '$PGDATA' -s" |
| 105 |
test -e "$PG_OOM_ADJUST_FILE" && echo "$PG_MASTER_OOM_SCORE_ADJ" > "$PG_OOM_ADJUST_FILE" |
| 106 |
su - $PGUSER -c "$DAEMON_ENV $DAEMON -D '$PGDATA' >>$PGLOG 2>&1 &" |
| 107 |
echo "ok" |
| 108 |
;; |
| 109 |
reload) |
| 110 |
echo -n "Reload PostgreSQL: " |
| 111 |
su - $PGUSER -c "$PGCTL reload -D '$PGDATA' -s" |
| 112 |
echo "ok" |
| 113 |
;; |
| 114 |
status) |
| 115 |
su - $PGUSER -c "$PGCTL status -D '$PGDATA'" |
| 116 |
;; |
| 117 |
*) |
| 118 |
# Print help |
| 119 |
echo "Usage: $0 {start|stop|restart|reload|status}" 1>&2 |
| 120 |
exit 1 |
| 121 |
;; |
| 122 |
esac |
| 123 |
|
| 124 |
exit 0 |