summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPavel Raiskup <praiskup@redhat.com>2015-03-20 11:51:49 +0100
committerPavel Raiskup <praiskup@redhat.com>2015-03-20 11:58:52 +0100
commitd529834d22549b48c54546d1fa463b93a0859025 (patch)
tree10018c9342c66d18bfef424b7c3485cc25dbc050
parentd95bc9eaaf44776349c05a44d42f3b84e574d936 (diff)
downloadpostgresql-setup-d529834d22549b48c54546d1fa463b93a0859025.tar.gz
postgresql-setup-d529834d22549b48c54546d1fa463b93a0859025.tar.xz
postgresql-setup-d529834d22549b48c54546d1fa463b93a0859025.zip
setup: enhance --new-systemd-unitv3.2
Do not left created dropin directory in case of some initdb failure, or so. This allow user run the same --new-systemd-unit repeatedly without changing the command-line. * postgresql-setup.in (exit_handler): New exit callback wrapper. ($cleanup_dropin): Code to be executed to clean drop-in directory. (generate_systemd_dropin): Fill $cleanup_dropin callback. (initdb): Clean $cleanup_dropin in case of successful initdb. This is not needed for upgrade() because we never create drop-ins there. * NEWS: Document changes.
-rw-r--r--NEWS5
-rw-r--r--postgresql-setup.in13
2 files changed, 18 insertions, 0 deletions
diff --git a/NEWS b/NEWS
index 42267d2..d4dc148 100644
--- a/NEWS
+++ b/NEWS
@@ -1,5 +1,10 @@
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+New in 3.1 version
+
+* The --new-systemd-unit option now cleans the recently created drop-in
+ directory if something goes wrong.
+
Bugfixes in 3.2 version
* Fix regression of setting the default pgdata variable for non-default
diff --git a/postgresql-setup.in b/postgresql-setup.in
index e4f640a..0337bdd 100644
--- a/postgresql-setup.in
+++ b/postgresql-setup.in
@@ -168,6 +168,7 @@ initdb()
info $"Initializing database in '$pgdata'$port_info"
if check_not_initialized && perform_initdb; then
info $"Initialized, logs are in ${initdb_log}"
+ cleanup_dropin=
else
error $"Initializing database failed, possibly see $initdb_log"
script_result=1
@@ -324,6 +325,8 @@ generate_systemd_dropin()
mkdir -p "$dropindir" \
|| die "Can not create '$dropindir'"
+ cleanup_dropin="rm -rf \"$dropindir\""
+
cat <<EOF > "$dropin" || die "Can not write to '$dropin'"
[Service]
Environment=PGDATA=$pgdata
@@ -502,6 +505,16 @@ service_configuration()
test -n "$envfile_pgport" && set_var "$portvar" "$envfile_pgport"
}
+cleanup_dropin=
+exit_handler()
+{
+ test -n "$cleanup_dropin" && {
+ info "cleaning up created dropin directory"
+ eval "$cleanup_dropin"
+ }
+}
+
+trap exit_handler 0
# <Compat>
# Alow users to use the old style arguments like