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

Fine-tune the new unshare code

parent a58e36ba
......@@ -106,10 +106,13 @@ loop() {
installcheck() {
prepare_env $1
if [ -z "$PG_VIRTUALENV_UNSHARE" ] && [ $(id -u) = 0 ]; then
# request new network namespace by default; override by setting
# PG_VIRTUALENV_UNSHARE (set to "--" to disable)
export PG_VIRTUALENV_UNSHARE="-n"
if [ "${PG_VIRTUALENV_UNSHARE-unset}" = "unset" ] && [ $(id -u) = 0 ]; then
export PG_VIRTUALENV_UNSHARE="-n" # request new network namespace by default
fi
# ask pg_virtualenv to create a non-system cluster
if [ "${NONROOT-unset}" = "unset" ]; then
export NONROOT=1
fi
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.
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
in parallel to share port 5432. Override by setting to a different value;
disable by setting to B<-->.
in parallel to share port 5432. Override by setting to a different value.
=head1 COMPATIBILITY
......
......@@ -581,7 +581,7 @@ foreach my $guc (@pgoptions) {
}
# 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';
}
......
......@@ -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)
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)$/) {
print "Redirecting $1 request to systemctl\n";
system ('systemctl', $1, "postgresql\@$version-$cluster");
......
......@@ -105,6 +105,7 @@ if [ "${NONROOT:-}" ]; then
fi
export PG_CLUSTER_CONF_ROOT="$WORKDIR/postgresql"
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
mkdir "$PGSYSCONFDIR" "$WORKDIR/log"
PWFILE="$PGSYSCONFDIR/pwfile"
......@@ -182,6 +183,7 @@ for v in $PG_VERSIONS; do
*) NOSYNC="--nosync" ;;
esac
pg_createcluster \
${PGPORT:+-p "$PGPORT"} \
${NONROOT:+-d "$WORKDIR/data/$v/regress"} \
${NONROOT:+-l "$WORKDIR/log/postgresql-$v-regress.log"} \
${CREATE_OPTS:-} "${PGCONF_OPTS[@]}" $v regress -- \
......
......@@ -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
these flags.
=item B<PGPORT>=I<n>
When set, the value is used for the (single) cluster created.
=back
=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