Commit b34c702c authored by Christoph Berg's avatar Christoph Berg

pg_buildext, pg_virtualenv: Add PG_VIRTUALENV_NEWPID and PG_VIRTUALENV_UNSHARE...

pg_buildext, pg_virtualenv: Add PG_VIRTUALENV_NEWPID and PG_VIRTUALENV_UNSHARE variables; pg_buildext selects unshare -n by default.
parent 0db99b25
......@@ -6,6 +6,8 @@ postgresql-common (170) UNRELEASED; urgency=medium
postgresql.service.wants.
* pg_dropcluster, pg_renamecluster: Handle stats_temp_directory.
* testsuite, pg_virtualenv: Remove the unshare hack, too much trouble.
* pg_buildext, pg_virtualenv: Add PG_VIRTUALENV_NEWPID and
PG_VIRTUALENV_UNSHARE variables; pg_buildext selects unshare -n by default.
* t/025_logging.t: Improve syslog detection in the test environment.
* pg_upgradecluster, t/030_errors.t: Unbreak after we changed the old=new
error message.
......
......@@ -106,6 +106,12 @@ 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"
fi
if [ "$target" ]; then # if target is given, use it, else stay in the top source dir
# if a Makefile was created by configure, use it, else the top level Makefile
[ -f $vtarget/Makefile ] || makefile="-f $srcdir/Makefile"
......
......@@ -212,6 +212,13 @@ configure the list of supported versions on your system.
=back
=head1 ENVIRONMENT
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<-->.
=head1 COMPATIBILITY
Earlier B<pg_buildext> versions required a "source dir" argument after the
......@@ -225,6 +232,8 @@ postgresql-server-dev-all (>= 148~).
B<pg_buildext installcheck> was introduced in postgresql-server-dev-all (>=
153~).
B<PG_VIRTUALENV_UNSHARE=-n> was introduced in postgresql-common (>= 170~).
=head1 SEE ALSO
C</usr/share/postgresql-common/supported-versions>, autopkgtest(1),
......
......@@ -386,6 +386,15 @@ if (($< == 0 or $> == 0) and $info{'configuid'} != 0 and
error "Config owner ($configowner:$info{configuid}) and data owner ($dataowner:$info{owneruid}) do not match, and config owner is not root";
}
# 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 ($action =~ /^(start|stop|restart)$/) {
print "Redirecting $1 request to systemctl\n";
system ('systemctl', $1, "postgresql\@$version-$cluster");
exit $? >> 8;
}
}
# recreate missing standard log dir
if ($> == 0 && ! -e '/var/log/postgresql' &&
$info{'logfile'} =~ m!^/var/log/postgresql!) {
......
......@@ -18,6 +18,28 @@
set -e # no -u here as that breaks PGCONF_OPTS[@]
# wrap ourselves in newpid if requested
if [ "$PG_VIRTUALENV_NEWPID" ]; then
unset PG_VIRTUALENV_NEWPID
exec newpid $0 "$@"
fi
# wrap ourselves in unshare if requested
if [ "$PG_VIRTUALENV_UNSHARE" ]; then
export _PG_VIRTUALENV_UNSHARE="$PG_VIRTUALENV_UNSHARE"
unset PG_VIRTUALENV_UNSHARE
exec unshare $_PG_VIRTUALENV_UNSHARE -- $0 "$@"
fi
if [ "$_PG_VIRTUALENV_UNSHARE" ]; then
unset _PG_VIRTUALENV_UNSHARE
# start localhost interface
if [ -x /bin/ip ]; then
ip link set dev lo up || true
else
ifconfig lo up || true
fi
fi
help ()
{
echo "pg_virtualenv: Create throw-away PostgreSQL environment for regression tests"
......
......@@ -78,6 +78,19 @@ Show program help.
When run with fakeroot(1), B<pg_virtualenv> will fall back to the non-root mode
of operation. Running "fakeroot pg_virtualenv" as root will fail, though.
=head1 ENVIRONMENT
=over 4
=item B<PG_VIRTUALENV_NEWPID>=yes
When non-empty, B<pg_virtualenv> will re-exec itself using newpid(1).
=item B<PG_VIRTUALENV_UNSHARE>=I<flags>
When non-empty, B<pg_virtualenv> will re-exec itself using unshare(1) using
these flags.
=head1 SEE ALSO
initdb(1), pg_createcluster(1).
......
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