Commit 9a2bf6b0 authored by Christoph Berg's avatar Christoph Berg

Fine-tune the new unshare code

parent a58e36ba
...@@ -106,10 +106,13 @@ loop() { ...@@ -106,10 +106,13 @@ loop() {
installcheck() { installcheck() {
prepare_env $1 prepare_env $1
if [ -z "$PG_VIRTUALENV_UNSHARE" ] && [ $(id -u) = 0 ]; then if [ "${PG_VIRTUALENV_UNSHARE-unset}" = "unset" ] && [ $(id -u) = 0 ]; then
# request new network namespace by default; override by setting export PG_VIRTUALENV_UNSHARE="-n" # request new network namespace by default
# PG_VIRTUALENV_UNSHARE (set to "--" to disable) fi
export PG_VIRTUALENV_UNSHARE="-n"
# ask pg_virtualenv to create a non-system cluster
if [ "${NONROOT-unset}" = "unset" ]; then
export NONROOT=1
fi fi
if [ "$target" ]; then # if target is given, use it, else stay in the top source dir if [ "$target" ]; then # if target is given, use it, else stay in the top source dir
......
...@@ -216,8 +216,7 @@ configure the list of supported versions on your system. ...@@ -216,8 +216,7 @@ configure the list of supported versions on your system.
B<pg_buildext> sets B<PG_VIRTUALENV_UNSHARE=-n> for the installcheck actions by B<pg_buildext> sets B<PG_VIRTUALENV_UNSHARE=-n> for the installcheck actions by
default to request a new network namespace, enabling several instances running default to request a new network namespace, enabling several instances running
in parallel to share port 5432. Override by setting to a different value; in parallel to share port 5432. Override by setting to a different value.
disable by setting to B<-->.
=head1 COMPATIBILITY =head1 COMPATIBILITY
......
...@@ -581,7 +581,7 @@ foreach my $guc (@pgoptions) { ...@@ -581,7 +581,7 @@ foreach my $guc (@pgoptions) {
} }
# notify systemd about the new cluster # notify systemd about the new cluster
if ($startconf eq 'auto' and -d '/var/run/systemd/system' and $euid == 0) { if (not exists $ENV{'PG_CLUSTER_CONF_ROOT'} and $startconf eq 'auto' and -d '/var/run/systemd/system' and $euid == 0) {
system 'systemctl daemon-reload'; system 'systemctl daemon-reload';
} }
......
...@@ -387,7 +387,7 @@ if (($< == 0 or $> == 0) and $info{'configuid'} != 0 and ...@@ -387,7 +387,7 @@ if (($< == 0 or $> == 0) and $info{'configuid'} != 0 and
} }
# redirect the request through systemd (if we are root and we are not a direct pid 1 child) # redirect the request through systemd (if we are root and we are not a direct pid 1 child)
if ($> == 0 and getppid() != 1 and not exists $ENV{_SYSTEMCTL_SKIP_REDIRECT}) { if ($> == 0 and getppid() != 1 and not exists $ENV{_SYSTEMCTL_SKIP_REDIRECT} and not exists $ENV{'PG_CLUSTER_CONF_ROOT'}) {
if ($action =~ /^(start|stop|restart)$/) { if ($action =~ /^(start|stop|restart)$/) {
print "Redirecting $1 request to systemctl\n"; print "Redirecting $1 request to systemctl\n";
system ('systemctl', $1, "postgresql\@$version-$cluster"); system ('systemctl', $1, "postgresql\@$version-$cluster");
......
...@@ -105,6 +105,7 @@ if [ "${NONROOT:-}" ]; then ...@@ -105,6 +105,7 @@ if [ "${NONROOT:-}" ]; then
fi fi
export PG_CLUSTER_CONF_ROOT="$WORKDIR/postgresql" export PG_CLUSTER_CONF_ROOT="$WORKDIR/postgresql"
export PGUSER="${USER:-${LOGNAME:-$(id -un)}}" export PGUSER="${USER:-${LOGNAME:-$(id -un)}}"
[ "$PGUSER" = "root" ] && PGUSER="postgres"
PGSYSCONFDIR="$WORKDIR/postgresql-common" # no export yet so pg_createcluster uses the original createcluster.conf PGSYSCONFDIR="$WORKDIR/postgresql-common" # no export yet so pg_createcluster uses the original createcluster.conf
mkdir "$PGSYSCONFDIR" "$WORKDIR/log" mkdir "$PGSYSCONFDIR" "$WORKDIR/log"
PWFILE="$PGSYSCONFDIR/pwfile" PWFILE="$PGSYSCONFDIR/pwfile"
...@@ -182,6 +183,7 @@ for v in $PG_VERSIONS; do ...@@ -182,6 +183,7 @@ for v in $PG_VERSIONS; do
*) NOSYNC="--nosync" ;; *) NOSYNC="--nosync" ;;
esac esac
pg_createcluster \ pg_createcluster \
${PGPORT:+-p "$PGPORT"} \
${NONROOT:+-d "$WORKDIR/data/$v/regress"} \ ${NONROOT:+-d "$WORKDIR/data/$v/regress"} \
${NONROOT:+-l "$WORKDIR/log/postgresql-$v-regress.log"} \ ${NONROOT:+-l "$WORKDIR/log/postgresql-$v-regress.log"} \
${CREATE_OPTS:-} "${PGCONF_OPTS[@]}" $v regress -- \ ${CREATE_OPTS:-} "${PGCONF_OPTS[@]}" $v regress -- \
......
...@@ -91,6 +91,10 @@ When non-empty, B<pg_virtualenv> will re-exec itself using newpid(1). ...@@ -91,6 +91,10 @@ When non-empty, B<pg_virtualenv> will re-exec itself using newpid(1).
When non-empty, B<pg_virtualenv> will re-exec itself using unshare(1) using When non-empty, B<pg_virtualenv> will re-exec itself using unshare(1) using
these flags. these flags.
=item B<PGPORT>=I<n>
When set, the value is used for the (single) cluster created.
=back =back
=head1 SEE ALSO =head1 SEE ALSO
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment