最近穷,开始卖手艺,会写脚本也是一门手艺, 觉得自己好low, 没有妹子爱
vim ~/pg.sh
#!/usr/bin/env bash
#export PG_PATH=/opt/pgsql96
#export PGDATA=/opt/pgsql96/data
export PG_PATH=/opt/pgsql
export PGDATA=/opt/pgsql/data
export PGUSER=postgres
install_db(){
useradd postgres
mkdir $PGDATA
chown postgres $PGDATA
}
fun_start(){
su $PGUSER -c "$PG_PATH/bin/pg_ctl -D $PGDATA start"
}
fun_stop(){
su $PGUSER -c "$PG_PATH/bin/pg_ctl -D $PGDATA stop"
}
status(){
su $PGUSER -c "$PG_PATH/bin/pg_ctl -D $PGDATA status"
}
fun_restart(){
su $PGUSER -c "$PG_PATH/bin/pg_ctl -D $PGDATA restart"
}
fun_reload(){
su $PGUSER -c "$PG_PATH/bin/pg_ctl -D $PGDATA reload"
}
case "$1" in
stop)
fun_stop
;;
start)
fun_start
;;
restart)
fun_restart
;;
status)
status
;;
reload)
reload
;;
*)
echo "usage: %"
esac
可以使用 sh pg.sh start | stop | status | restart