lede-packages-rs

git clone git://archive.git.mtrnord.blog/MTRNord/lede-packages-rs.git
Log | Files | Refs | README | LICENSE

postgresql.init (1702B)


      1 #!/bin/sh /etc/rc.common
      2 # Copyright (C) 2006-2015 OpenWrt.org
      3 START=50
      4 
      5 PROG=/usr/bin/postmaster
      6 
      7 USE_PROCD=1
      8 
      9 EXTRA_COMMANDS="status"
     10 EXTRA_HELP="        status  Show current status of the PostgreSQL server"
     11 
     12 fix_hosts() {
     13 	# make sure localhost (without a dot) is in /etc/hosts
     14 	grep -q 'localhost$' /etc/hosts || echo '127.0.0.1 localhost' >> /etc/hosts
     15 }
     16 
     17 fix_perms() {
     18 	# for whatever reason, /dev/null gets wrong perms
     19 	chmod a+w /dev/null
     20 }
     21 
     22 cleanup() {
     23 	if [ -f "$1/postmaster.pid" ]; then
     24 		rm "$1/postmaster.pid"
     25 	fi
     26 }
     27 
     28 start_service() {
     29 	. /lib/functions/postgresql.sh
     30 
     31 	config_load "postgresql"
     32 	config_get pgdata config PGDATA
     33 	config_get pgopts config PGOPTS
     34 
     35 	user_exists postgres 5432 || user_add postgres 5432
     36 	group_exists postgres 5432 || group_add postgres 5432
     37 
     38 	fix_perms
     39 	fix_hosts
     40 
     41 	if [ ! -d "${pgdata}" ]; then
     42 		pg_init_data ${pgdata}
     43 		[ $? -gt 0 ] && return 1
     44 	fi
     45 
     46 	cleanup "${pgdata}"
     47 
     48 	procd_open_instance
     49 	procd_set_param user postgres
     50 	procd_set_param command $PROG
     51 	procd_append_param command -D "${pgdata}"
     52 	[ -n "${pgopts}" ] && procd_append_param command -o "${pgopts}"
     53 	procd_set_param respawn retry=60
     54 	procd_close_instance
     55 
     56 	procd_open_instance
     57 	procd_set_param user postgres
     58 	procd_set_param command /lib/functions/postgresql.sh init "${pgdata}"
     59 	procd_close_instance
     60 }
     61 
     62 reload_service() {
     63 	config_load "postgresql"
     64 	config_get pgdata config PGDATA
     65 	/usr/bin/pg_ctl reload -U postgres -D "${pgdata}" -s
     66 }
     67 
     68 stop_service() {
     69 	config_load "postgresql"
     70 	config_get pgdata config PGDATA
     71 	/usr/bin/pg_ctl stop -U postgres -D "${pgdata}" -s
     72 }
     73 
     74 status() {
     75 	config_load "postgresql"
     76 	config_get pgdata config PGDATA
     77 	/usr/bin/pg_ctl status -U postgres -D "${pgdata}"
     78 }