Skip to content

Commit 86e6bb8

Browse files
committed
* postgresql-setup.in: Drop the root permissions ASAP, at the beginning of the script. Removing --datadir and --new-systemd-unit options. Removing the direct calls to chown/chmod, since we create the files under 'postgres' user, and we have set the umask to 0077. The root_prereq call dropped, the script can be run directly by 'postgres' user now. ($RESTORECON, $USER): New helper variables. ($SU_POSTGRES): Dropped, since we don't need to drop root permissions on multiple places. (generate_systemd_dropin, exit_handler): Drop this functions, not needed since we don't support --new-systemd-unit option now. (upgrade): Don't add semicolon into env-var hacks, since we separate the hacks by new-line, semicolon is redundant. Switching from run_cmd_as_dbadmin to direct call (su is not needed), but to keep the semantics of env-var hacks we need to 'eval' them (so closing the env-hacks into parentheses to not affect script variables. * postgresql.init.in ($RESTORECON): New helper variable, must be always set to some value, even when /sbin/restorecon is not found. (admin_cmd): Replacement for run_cmd_as_dbadmin from library, but now working better with arguments which need to be quoted. Also setting umask automatically. (start): Use 'admin_cmd' instead of working with files under root, or using run_cmd_as_dbadmin. * sbin/new-systemd-unit.in: New helper script as a replacement for the --new-systemd-unit option in postgresql-setup. * share/postgresql-setup/library.sh.in (root_prereq): Since this is now used in early state of *-new-systemd-unit script, we need to reflect $PGSETUP_TEST variable to be able to run help2man script. (run_cmd_as_dbadmin): Dropped, no script needs this. * configure.ac (PGADMINUSER): New substitution. (SU_POSTGRES): Use PGADMINUSER, allows distributors to replace the username. (SCL_SOURCE): Always define to some value (true by default), this simplifies working with the @SCL_SOURCE@ pattern. Drop the trailing semicolon, callers should do this. * doc/Makefile.inc: Generate new $(new_unit_man) manpage. Install it only on systemd-aware systems. * sbin/Makefile.inc: New file. * .gitignore: Ignore new script under sbin/ directory. * Makefile.am: Reflect new build subdir sbin/. * README.rpm-dist.template: Document the (new) way how to automatically generate new systemd unit.
1 parent 114cc70 commit 86e6bb8

11 files changed

+295
-165
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ macros.postgresql*
2020
package.m4
2121
postgresql*-check-db-dir
2222
postgresql*-ctl
23+
postgresql*-new-systemd-unit
2324
postgresql*.service
2425
/postgresql*-setup
2526
postgresql*-setup.1

Makefile.am

+2
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,12 @@ EXTRA_DIST += \
114114

115115
include $(srcdir)/share/postgresql-setup/Makefile.inc
116116
include $(srcdir)/lib/rpm/Makefile.inc
117+
include $(srcdir)/sbin/Makefile.inc
117118
include $(srcdir)/doc/Makefile.inc
118119

119120
GENERATED_FILES += \
120121
$(bin_SCRIPTS) \
122+
$(sbin_SCRIPTS) \
121123
$(libexec_SCRIPTS) \
122124
$(pgdoc_DATA) \
123125
$(pkgsysconf_DATA) \

NEWS

+8
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@ Bugfixes in 6.0 version
44

55
* Dropped dependency on /bin/find utility.
66

7+
* The postgresql-setup doesn't need root permissions. It is better to not
8+
run this script as 'root' user from now.
9+
10+
Incompatible changes in 6.0 version
11+
12+
* The postgresql-setup doesn't support --new-systemd-unit option. Please use
13+
postgresql-new-systemd-unit script instead (as 'root').
14+
715
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
816

917
Bugfixes in 5.1 version

README.rpm-dist.template

+9-4
Original file line numberDiff line numberDiff line change
@@ -396,14 +396,19 @@ m4_ifelse([@WANT_SYSVINIT@], [1], m4_dnl
396396
<orderedlist>
397397
<listitem>
398398
<para>
399-
Run the following command to create the necessary configuration and to
400-
initialize the new database cluster
399+
Run the following command to create the necessary systemd configuration:
400+
</para>
401+
<screen>
402+
<prompt># </prompt><userinput>@NAME_BINARYBASE@-new-systemd-unit \</userinput>
403+
<userinput> --unit postgresql@secondary \</userinput>
404+
<userinput> --datadir /path/to/data/directory</userinput>
405+
</screen>
406+
<para>
407+
And then run this command to initialize the new database cluster:
401408
</para>
402409
<screen>
403410
<prompt>$ </prompt><userinput>@NAME_BINARYBASE@-setup --initdb \</userinput>
404411
<userinput> --unit postgresql@secondary \</userinput>
405-
<userinput> --new-systemd-unit \</userinput>
406-
<userinput> --datadir /path/to/data/directory \</userinput>
407412
<userinput> --port NNNN</userinput>
408413
</screen>
409414
<para>

configure.ac

+6-3
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,10 @@ test -z "$ac_cv_path_SED" &&
6969
AC_PATH_PROGS([SU], [runuser su])
7070
test -z "$ac_cv_path_SU" &&
7171
AC_MSG_ERROR([Neither 'runuser' nor 'su' program found])
72-
SU_POSTGRES="$SU -s /bin/sh -l postgres"
72+
73+
PGSETUP_SUBST_OPT([PGADMINUSER], [postgres],
74+
[System-default PostgreSQL admin username])
75+
SU_POSTGRES="$SU -s /bin/sh -l $PGADMINUSER"
7376
_AX_TEXT_TPL_SUBST([SU_POSTGRES])
7477

7578
AC_PATH_PROG([MOUNTPOINT], [mountpoint], [false])
@@ -154,12 +157,12 @@ PGSETUP_SUBST_OPT([SCLS], [],
154157

155158
SCL_BINDIR=/usr/bin
156159
SCL_BINARY=scl
157-
SCL_SOURCE=
160+
SCL_SOURCE=:
158161
SCL_SHELL_WRAPPER=
159162
if test -n "$SCLS"
160163
then
161164
SCL_SHELL_WRAPPER="$SCL_BINDIR/$SCL_BINARY enable $SCLS -- "
162-
SCL_SOURCE="source scl_source enable $SCLS ;"
165+
SCL_SOURCE="source scl_source enable $SCLS"
163166
fi
164167

165168
_AX_TEXT_TPL_SUBST([SCL_SHELL_WRAPPER])

doc/Makefile.inc

+13-1
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,23 @@ HELP2MAN_RUN = \
2323

2424
setup_man = %D%/$(NAME_BINARYBASE)-setup.1
2525

26+
new_unit_man = %D%/$(NAME_BINARYBASE)-new-systemd-unit.1
27+
2628
dist_man_MANS = $(setup_man)
2729

30+
if ! WANT_SYSVINIT
31+
dist_man_MANS += $(new_unit_man)
32+
endif
33+
2834
$(setup_man): $(NAME_BINARYBASE)-setup
2935
$(AM_V_GEN)odir=`dirname "$@"` ; mkdir -p "$$odir" ; \
3036
export input=$(builddir)/$(NAME_BINARYBASE)-setup ; \
3137
$(HELP2MAN_RUN)
3238

33-
DISTCLEANFILES += $(setup_man)
39+
$(new_unit_man): sbin/$(NAME_BINARYBASE)-new-systemd-unit
40+
$(AM_V_GEN)odir=`dirname "$@"`; mkdir -p "$$odir" ; \
41+
export PGSETUP_TEST=: ; \
42+
export input=$(builddir)/sbin/$(NAME_BINARYBASE)-new-systemd-unit ; \
43+
$(HELP2MAN_RUN)
44+
45+
DISTCLEANFILES += $(setup_man) $(new_unit_man)

0 commit comments

Comments
 (0)