PDF docs build: avoid spurious "warn" in build logs.
[pgsql.git] / contrib / start-scripts / linux
blobca01e96a62bfc8268c5172548d00f0f3492d83e7
1 #! /bin/sh
3 # chkconfig: 2345 98 02
4 # description: PostgreSQL RDBMS
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.
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
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.
25 # Original author: Ryan Kirkpatrick <pgsql@rkirkpat.net>
27 # contrib/start-scripts/linux
29 ## EDIT FROM HERE
31 # Installation prefix
32 prefix=/usr/local/pgsql
34 # Data directory
35 PGDATA="/usr/local/pgsql/data"
37 # Who to run postgres as, usually "postgres". (NOT "root")
38 PGUSER=postgres
40 # Where to keep a log file
41 PGLOG="$PGDATA/serverlog"
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
57 ## STOP EDITING HERE
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
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"
66 # What to use to shut down postgres
67 PGCTL="$prefix/bin/pg_ctl"
69 set -e
71 # Only start if we can find postgres.
72 test -x $DAEMON ||
74 echo "$DAEMON not found"
75 if [ "$1" = "stop" ]
76 then exit 0
77 else exit 5
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"
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"
97 stop)
98 echo -n "Stopping PostgreSQL: "
99 su - $PGUSER -c "$PGCTL stop -D '$PGDATA' -s"
100 echo "ok"
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"
109 reload)
110 echo -n "Reload PostgreSQL: "
111 su - $PGUSER -c "$PGCTL reload -D '$PGDATA' -s"
112 echo "ok"
114 status)
115 su - $PGUSER -c "$PGCTL status -D '$PGDATA'"
118 # Print help
119 echo "Usage: $0 {start|stop|restart|reload|status}" 1>&2
120 exit 1
122 esac
124 exit 0