Add postgresql init script

This commit is contained in:
Calin Crisan 2019-01-25 22:28:53 +02:00
parent ccaf32fe2a
commit 29541688bf
2 changed files with 70 additions and 0 deletions

View File

@ -208,6 +208,7 @@ rm -f ${TARGET}/etc/init.d/S20urandom
rm -f ${TARGET}/etc/init.d/S49ntp
rm -f ${TARGET}/etc/init.d/S50sshd
rm -f ${TARGET}/etc/init.d/S50proftpd
rm -f ${TARGET}/etc/init.d/S50postgresql
rm -f ${TARGET}/etc/init.d/S50redis
rm -f ${TARGET}/etc/init.d/S80dhcp-relay
rm -f ${TARGET}/etc/init.d/S80dhcp-server

View File

@ -0,0 +1,69 @@
#!/bin/bash
BOOT_CONF="/boot/postgresql.conf"
SYS_CONF="/etc/postgresql.conf"
CONF="/data/etc/postgresql.conf"
PROG="/usr/bin/pg_ctl"
DB_DIR="/var/lib/postgresql"
USER="postgres"
LOG="/var/log/postgresql.log"
function run_pg_ctl() {
su ${USER} -c "pg_ctl $*"
}
test -x ${PROG} || exit 0
test -n "${OS_VERSION}" || source /etc/init.d/base
prepare_conf ${CONF} ${SYS_CONF} ${BOOT_CONF}
start() {
mkdir -p ${DB_DIR}
chown -R ${USER} ${DB_DIR}
touch ${LOG}
chown ${USER} ${LOG}
if [[ ! -f ${DB_DIR}/PG_VERSION ]]; then
msg_begin "Initializing postgresql db"
run_pg_ctl initdb -s -D ${DB_DIR} &>> ${LOG}
test $? == 0 && msg_done || msg_fail
echo "include_if_exists = '/data/etc/postgresql.conf'" >> ${DB_DIR}/postgresql.conf
fi
msg_begin "Starting postgresql"
run_pg_ctl start -s -D ${DB_DIR} -l ${LOG}
test $? == 0 && msg_done || msg_fail
}
stop() {
msg_begin "Stopping postgresql"
run_pg_ctl stop -s -D ${DB_DIR} -m fast &>> ${LOG}
test $? == 0 && msg_done || msg_fail
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
*)
echo "Usage: $0 {start|stop|restart}"
exit 1
esac