Skip to content

Commit d529834

Browse files
committed
setup: enhance --new-systemd-unit
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.
1 parent d95bc9e commit d529834

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

NEWS

+5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
22

3+
New in 3.1 version
4+
5+
* The --new-systemd-unit option now cleans the recently created drop-in
6+
directory if something goes wrong.
7+
38
Bugfixes in 3.2 version
49

510
* Fix regression of setting the default pgdata variable for non-default

postgresql-setup.in

+13
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ initdb()
168168
info $"Initializing database in '$pgdata'$port_info"
169169
if check_not_initialized && perform_initdb; then
170170
info $"Initialized, logs are in ${initdb_log}"
171+
cleanup_dropin=
171172
else
172173
error $"Initializing database failed, possibly see $initdb_log"
173174
script_result=1
@@ -324,6 +325,8 @@ generate_systemd_dropin()
324325
mkdir -p "$dropindir" \
325326
|| die "Can not create '$dropindir'"
326327

328+
cleanup_dropin="rm -rf \"$dropindir\""
329+
327330
cat <<EOF > "$dropin" || die "Can not write to '$dropin'"
328331
[Service]
329332
Environment=PGDATA=$pgdata
@@ -502,6 +505,16 @@ service_configuration()
502505
test -n "$envfile_pgport" && set_var "$portvar" "$envfile_pgport"
503506
}
504507

508+
cleanup_dropin=
509+
exit_handler()
510+
{
511+
test -n "$cleanup_dropin" && {
512+
info "cleaning up created dropin directory"
513+
eval "$cleanup_dropin"
514+
}
515+
}
516+
517+
trap exit_handler 0
505518

506519
# <Compat>
507520
# Alow users to use the old style arguments like

0 commit comments

Comments
 (0)