move exit trap to function
This commit is contained in:
parent
2c41800782
commit
719c03887d
|
@ -4,6 +4,11 @@ log() {
|
|||
printf '\e[1m\e[38;5;87m==>\e[0m\e[1m %s.\e[0m\n' "$*"
|
||||
}
|
||||
|
||||
exitHook() {
|
||||
log "Stopping postgres"
|
||||
pg_ctl stop --pgdata=./matabas-db
|
||||
}
|
||||
|
||||
log "Checking for existing postgres directory"
|
||||
[ -d ./matabas-db ] || {
|
||||
log "Non-existent, creating postgres directory (./matabas-db)"
|
||||
|
@ -18,7 +23,7 @@ log "Checking for existing postgres directory"
|
|||
|
||||
log "Starting postgres"
|
||||
pg_ctl start --pgdata=./matabas-db --log=./matabas-db/matabas.log --options="-p 2137 -k /tmp"
|
||||
trap 'log "Stopping postgres" && pg_ctl stop --pgdata=./matabas-db' EXIT
|
||||
trap exitHook EXIT
|
||||
|
||||
log "Creating database"
|
||||
createdb -p 2137 matabas 2>>./matabas-db/matabas.log || log "Database already exists, not overwriting"
|
||||
|
|
Loading…
Reference in New Issue
Block a user