databases/postgresql/postgresql

Fri, 15 Nov 2019 20:05:00 +0100

author
David Demelier <markand@malikania.fr>
date
Fri, 15 Nov 2019 20:05:00 +0100
changeset 1207
c9592a9a949b
parent 1169
194681a6d42d
permissions
-rw-r--r--

python/python2: add DEPRECATED tag

1169
194681a6d42d databases/postgresql: initial import, closes #2411
David Demelier <markand@malikania.fr>
parents:
diff changeset
1 #!/bin/busybox sh
194681a6d42d databases/postgresql: initial import, closes #2411
David Demelier <markand@malikania.fr>
parents:
diff changeset
2 #
194681a6d42d databases/postgresql: initial import, closes #2411
David Demelier <markand@malikania.fr>
parents:
diff changeset
3 # /etc/rc.d/postgresql -- run control script for postgresql
194681a6d42d databases/postgresql: initial import, closes #2411
David Demelier <markand@malikania.fr>
parents:
diff changeset
4 #
194681a6d42d databases/postgresql: initial import, closes #2411
David Demelier <markand@malikania.fr>
parents:
diff changeset
5 # Copyright (c) 2019 David Demelier <markand@malikania.fr>
194681a6d42d databases/postgresql: initial import, closes #2411
David Demelier <markand@malikania.fr>
parents:
diff changeset
6 #
194681a6d42d databases/postgresql: initial import, closes #2411
David Demelier <markand@malikania.fr>
parents:
diff changeset
7 # Permission to use, copy, modify, and/or distribute this software for any
194681a6d42d databases/postgresql: initial import, closes #2411
David Demelier <markand@malikania.fr>
parents:
diff changeset
8 # purpose with or without fee is hereby granted, provided that the above
194681a6d42d databases/postgresql: initial import, closes #2411
David Demelier <markand@malikania.fr>
parents:
diff changeset
9 # copyright notice and this permission notice appear in all copies.
194681a6d42d databases/postgresql: initial import, closes #2411
David Demelier <markand@malikania.fr>
parents:
diff changeset
10 #
194681a6d42d databases/postgresql: initial import, closes #2411
David Demelier <markand@malikania.fr>
parents:
diff changeset
11 # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
194681a6d42d databases/postgresql: initial import, closes #2411
David Demelier <markand@malikania.fr>
parents:
diff changeset
12 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
194681a6d42d databases/postgresql: initial import, closes #2411
David Demelier <markand@malikania.fr>
parents:
diff changeset
13 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
194681a6d42d databases/postgresql: initial import, closes #2411
David Demelier <markand@malikania.fr>
parents:
diff changeset
14 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
194681a6d42d databases/postgresql: initial import, closes #2411
David Demelier <markand@malikania.fr>
parents:
diff changeset
15 # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
194681a6d42d databases/postgresql: initial import, closes #2411
David Demelier <markand@malikania.fr>
parents:
diff changeset
16 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
194681a6d42d databases/postgresql: initial import, closes #2411
David Demelier <markand@malikania.fr>
parents:
diff changeset
17 # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
194681a6d42d databases/postgresql: initial import, closes #2411
David Demelier <markand@malikania.fr>
parents:
diff changeset
18 #
194681a6d42d databases/postgresql: initial import, closes #2411
David Demelier <markand@malikania.fr>
parents:
diff changeset
19
194681a6d42d databases/postgresql: initial import, closes #2411
David Demelier <markand@malikania.fr>
parents:
diff changeset
20 if [ -f /etc/rc.conf ]; then
194681a6d42d databases/postgresql: initial import, closes #2411
David Demelier <markand@malikania.fr>
parents:
diff changeset
21 . /etc/rc.conf
194681a6d42d databases/postgresql: initial import, closes #2411
David Demelier <markand@malikania.fr>
parents:
diff changeset
22 fi
194681a6d42d databases/postgresql: initial import, closes #2411
David Demelier <markand@malikania.fr>
parents:
diff changeset
23
194681a6d42d databases/postgresql: initial import, closes #2411
David Demelier <markand@malikania.fr>
parents:
diff changeset
24 : ${POSTGRESQL_PID:=/var/run/postgresql/postgresql.pid}
194681a6d42d databases/postgresql: initial import, closes #2411
David Demelier <markand@malikania.fr>
parents:
diff changeset
25 : ${POSTGRESQL_USER:=postgresql}
194681a6d42d databases/postgresql: initial import, closes #2411
David Demelier <markand@malikania.fr>
parents:
diff changeset
26 : ${POSTGRESQL_GROUP:=postgresql}
194681a6d42d databases/postgresql: initial import, closes #2411
David Demelier <markand@malikania.fr>
parents:
diff changeset
27 : ${POSTGRESQL_DIR:=/var/db/postgresql}
194681a6d42d databases/postgresql: initial import, closes #2411
David Demelier <markand@malikania.fr>
parents:
diff changeset
28 : ${POSTGRESQL_CMD:=/bin/postgres}
194681a6d42d databases/postgresql: initial import, closes #2411
David Demelier <markand@malikania.fr>
parents:
diff changeset
29 : ${POSTGRESQL_ARGS:=-D ${POSTGRESQL_DIR}}
194681a6d42d databases/postgresql: initial import, closes #2411
David Demelier <markand@malikania.fr>
parents:
diff changeset
30
194681a6d42d databases/postgresql: initial import, closes #2411
David Demelier <markand@malikania.fr>
parents:
diff changeset
31 postgresql_start()
194681a6d42d databases/postgresql: initial import, closes #2411
David Demelier <markand@malikania.fr>
parents:
diff changeset
32 {
194681a6d42d databases/postgresql: initial import, closes #2411
David Demelier <markand@malikania.fr>
parents:
diff changeset
33 mkdir -p $(dirname $POSTGRESQL_PID)
194681a6d42d databases/postgresql: initial import, closes #2411
David Demelier <markand@malikania.fr>
parents:
diff changeset
34
194681a6d42d databases/postgresql: initial import, closes #2411
David Demelier <markand@malikania.fr>
parents:
diff changeset
35 if [ -s $POSTGRESQL_PID ]; then
194681a6d42d databases/postgresql: initial import, closes #2411
David Demelier <markand@malikania.fr>
parents:
diff changeset
36 echo "postgresql is already running with pid: $(cat $POSTGRESQL_PID)"
194681a6d42d databases/postgresql: initial import, closes #2411
David Demelier <markand@malikania.fr>
parents:
diff changeset
37 else
194681a6d42d databases/postgresql: initial import, closes #2411
David Demelier <markand@malikania.fr>
parents:
diff changeset
38 echo "Starting postgresql: $POSTGRESQL_CMD $POSTGRESQL_ARGS"
194681a6d42d databases/postgresql: initial import, closes #2411
David Demelier <markand@malikania.fr>
parents:
diff changeset
39 start-stop-daemon \
194681a6d42d databases/postgresql: initial import, closes #2411
David Demelier <markand@malikania.fr>
parents:
diff changeset
40 -Sbmvp $POSTGRESQL_PID \
194681a6d42d databases/postgresql: initial import, closes #2411
David Demelier <markand@malikania.fr>
parents:
diff changeset
41 -c $POSTGRESQL_USER:$POSTGRESQL_GROUP \
194681a6d42d databases/postgresql: initial import, closes #2411
David Demelier <markand@malikania.fr>
parents:
diff changeset
42 -x $POSTGRESQL_CMD -- $POSTGRESQL_ARGS
194681a6d42d databases/postgresql: initial import, closes #2411
David Demelier <markand@malikania.fr>
parents:
diff changeset
43 fi
194681a6d42d databases/postgresql: initial import, closes #2411
David Demelier <markand@malikania.fr>
parents:
diff changeset
44 }
194681a6d42d databases/postgresql: initial import, closes #2411
David Demelier <markand@malikania.fr>
parents:
diff changeset
45
194681a6d42d databases/postgresql: initial import, closes #2411
David Demelier <markand@malikania.fr>
parents:
diff changeset
46 postgresql_init()
194681a6d42d databases/postgresql: initial import, closes #2411
David Demelier <markand@malikania.fr>
parents:
diff changeset
47 {
194681a6d42d databases/postgresql: initial import, closes #2411
David Demelier <markand@malikania.fr>
parents:
diff changeset
48 mkdir -p $POSTGRESQL_DIR
194681a6d42d databases/postgresql: initial import, closes #2411
David Demelier <markand@malikania.fr>
parents:
diff changeset
49 chown $POSTGRESQL_USER:$POSTGRESQL_GROUP $POSTGRESQL_DIR
194681a6d42d databases/postgresql: initial import, closes #2411
David Demelier <markand@malikania.fr>
parents:
diff changeset
50 busybox su $POSTGRESQL_USER -lp -c "pg_ctl -D $POSTGRESQL_DIR initdb"
194681a6d42d databases/postgresql: initial import, closes #2411
David Demelier <markand@malikania.fr>
parents:
diff changeset
51 }
194681a6d42d databases/postgresql: initial import, closes #2411
David Demelier <markand@malikania.fr>
parents:
diff changeset
52
194681a6d42d databases/postgresql: initial import, closes #2411
David Demelier <markand@malikania.fr>
parents:
diff changeset
53 postgresql_status()
194681a6d42d databases/postgresql: initial import, closes #2411
David Demelier <markand@malikania.fr>
parents:
diff changeset
54 {
194681a6d42d databases/postgresql: initial import, closes #2411
David Demelier <markand@malikania.fr>
parents:
diff changeset
55 if [ -s $POSTGRESQL_PID ]; then
194681a6d42d databases/postgresql: initial import, closes #2411
David Demelier <markand@malikania.fr>
parents:
diff changeset
56 echo "postgresql is running with pid: $(cat $POSTGRESQL_PID)"
194681a6d42d databases/postgresql: initial import, closes #2411
David Demelier <markand@malikania.fr>
parents:
diff changeset
57 else
194681a6d42d databases/postgresql: initial import, closes #2411
David Demelier <markand@malikania.fr>
parents:
diff changeset
58 echo "postgresql is not running"
194681a6d42d databases/postgresql: initial import, closes #2411
David Demelier <markand@malikania.fr>
parents:
diff changeset
59 fi
194681a6d42d databases/postgresql: initial import, closes #2411
David Demelier <markand@malikania.fr>
parents:
diff changeset
60 }
194681a6d42d databases/postgresql: initial import, closes #2411
David Demelier <markand@malikania.fr>
parents:
diff changeset
61
194681a6d42d databases/postgresql: initial import, closes #2411
David Demelier <markand@malikania.fr>
parents:
diff changeset
62 postgresql_stop()
194681a6d42d databases/postgresql: initial import, closes #2411
David Demelier <markand@malikania.fr>
parents:
diff changeset
63 {
194681a6d42d databases/postgresql: initial import, closes #2411
David Demelier <markand@malikania.fr>
parents:
diff changeset
64 if [ -s $POSTGRESQL_PID ]; then
194681a6d42d databases/postgresql: initial import, closes #2411
David Demelier <markand@malikania.fr>
parents:
diff changeset
65 echo "Stopping postgresql."
194681a6d42d databases/postgresql: initial import, closes #2411
David Demelier <markand@malikania.fr>
parents:
diff changeset
66 start-stop-daemon -Kqp $POSTGRESQL_PID
194681a6d42d databases/postgresql: initial import, closes #2411
David Demelier <markand@malikania.fr>
parents:
diff changeset
67 rm -f $POSTGRESQL_PID
194681a6d42d databases/postgresql: initial import, closes #2411
David Demelier <markand@malikania.fr>
parents:
diff changeset
68 fi
194681a6d42d databases/postgresql: initial import, closes #2411
David Demelier <markand@malikania.fr>
parents:
diff changeset
69 }
194681a6d42d databases/postgresql: initial import, closes #2411
David Demelier <markand@malikania.fr>
parents:
diff changeset
70
194681a6d42d databases/postgresql: initial import, closes #2411
David Demelier <markand@malikania.fr>
parents:
diff changeset
71 postgresql_restart()
194681a6d42d databases/postgresql: initial import, closes #2411
David Demelier <markand@malikania.fr>
parents:
diff changeset
72 {
194681a6d42d databases/postgresql: initial import, closes #2411
David Demelier <markand@malikania.fr>
parents:
diff changeset
73 postgresql_stop
194681a6d42d databases/postgresql: initial import, closes #2411
David Demelier <markand@malikania.fr>
parents:
diff changeset
74 sleep 3
194681a6d42d databases/postgresql: initial import, closes #2411
David Demelier <markand@malikania.fr>
parents:
diff changeset
75 postgresql_start
194681a6d42d databases/postgresql: initial import, closes #2411
David Demelier <markand@malikania.fr>
parents:
diff changeset
76 }
194681a6d42d databases/postgresql: initial import, closes #2411
David Demelier <markand@malikania.fr>
parents:
diff changeset
77
194681a6d42d databases/postgresql: initial import, closes #2411
David Demelier <markand@malikania.fr>
parents:
diff changeset
78 case $1 in
194681a6d42d databases/postgresql: initial import, closes #2411
David Demelier <markand@malikania.fr>
parents:
diff changeset
79 init)
194681a6d42d databases/postgresql: initial import, closes #2411
David Demelier <markand@malikania.fr>
parents:
diff changeset
80 postgresql_init
194681a6d42d databases/postgresql: initial import, closes #2411
David Demelier <markand@malikania.fr>
parents:
diff changeset
81 ;;
194681a6d42d databases/postgresql: initial import, closes #2411
David Demelier <markand@malikania.fr>
parents:
diff changeset
82 start)
194681a6d42d databases/postgresql: initial import, closes #2411
David Demelier <markand@malikania.fr>
parents:
diff changeset
83 postgresql_start
194681a6d42d databases/postgresql: initial import, closes #2411
David Demelier <markand@malikania.fr>
parents:
diff changeset
84 ;;
194681a6d42d databases/postgresql: initial import, closes #2411
David Demelier <markand@malikania.fr>
parents:
diff changeset
85 status)
194681a6d42d databases/postgresql: initial import, closes #2411
David Demelier <markand@malikania.fr>
parents:
diff changeset
86 postgresql_status
194681a6d42d databases/postgresql: initial import, closes #2411
David Demelier <markand@malikania.fr>
parents:
diff changeset
87 ;;
194681a6d42d databases/postgresql: initial import, closes #2411
David Demelier <markand@malikania.fr>
parents:
diff changeset
88 stop)
194681a6d42d databases/postgresql: initial import, closes #2411
David Demelier <markand@malikania.fr>
parents:
diff changeset
89 postgresql_stop
194681a6d42d databases/postgresql: initial import, closes #2411
David Demelier <markand@malikania.fr>
parents:
diff changeset
90 ;;
194681a6d42d databases/postgresql: initial import, closes #2411
David Demelier <markand@malikania.fr>
parents:
diff changeset
91 restart)
194681a6d42d databases/postgresql: initial import, closes #2411
David Demelier <markand@malikania.fr>
parents:
diff changeset
92 postgresql_restart
194681a6d42d databases/postgresql: initial import, closes #2411
David Demelier <markand@malikania.fr>
parents:
diff changeset
93 ;;
194681a6d42d databases/postgresql: initial import, closes #2411
David Demelier <markand@malikania.fr>
parents:
diff changeset
94 *)
194681a6d42d databases/postgresql: initial import, closes #2411
David Demelier <markand@malikania.fr>
parents:
diff changeset
95 echo "usage: $(basename $0) init|restart|start|status|stop"
194681a6d42d databases/postgresql: initial import, closes #2411
David Demelier <markand@malikania.fr>
parents:
diff changeset
96 ;;
194681a6d42d databases/postgresql: initial import, closes #2411
David Demelier <markand@malikania.fr>
parents:
diff changeset
97 esac

mercurial