postgres_master.pp: Fix wacky su command line.

The construction `su postgres -c -- bash -c 'psql …'` didn’t behave the
way it reads, and only worked by accident:

1. `-c --` sets the command to `--`.
2. `bash` sets the first argument to `bash`.
3. `-c 'psql …'` replaces the command with `psql …`.

Thus, `su` ended up executing `<shell> -c 'psql …' bash`, where
`<shell>` is the `postgres` user’s login shell, usually also `bash`,
which then executed 'psql …' and ignored the extra `bash`.

Unconfuse this construction.

Note from tabbott: The old code didn't even work by accident, it was
just broken.  The right fix is to move the quoting around properly.

Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
This commit is contained in:
Anders Kaseorg 2019-04-12 16:40:36 -07:00 committed by Tim Abbott
parent 460abe82df
commit 9f7c0b7e65
1 changed files with 1 additions and 1 deletions

View File

@ -33,7 +33,7 @@ class zulip_ops::postgres_master {
# This one will probably fail most of the time
exec {'give_nagios_user_access':
# lint:ignore:140chars
command => "su postgres -c -- bash -c 'psql -v ON_ERROR_STOP=1 zulip < /usr/share/postgresql/${zulip::base::postgres_version}/zulip_nagios_setup.sql' && touch /usr/share/postgresql/${zulip::base::postgres_version}/zulip_nagios_setup.sql.applied",
command => "bash -c \"su postgres -c 'psql -v ON_ERROR_STOP=1 zulip < /usr/share/postgresql/${zulip::base::postgres_version}/zulip_nagios_setup.sql' && touch /usr/share/postgresql/${zulip::base::postgres_version}/zulip_nagios_setup.sql.applied\"",
# lint:endignore
creates => "/usr/share/postgresql/${zulip::base::postgres_version}/zulip_nagios_setup.sql.applied",
require => Package["postgresql-${zulip::base::postgres_version}"],