puppet: Use pgrep -x to avoid accidental matches.

Matching the full process name (-x without -f) or full command
line (-xf) is less prone to mistakes like matching a random substring
of some other command line or pgrep matching itself.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg 2021-05-03 15:20:04 -07:00 committed by Tim Abbott
parent 9e243c74ed
commit 9d57fa9759
5 changed files with 5 additions and 5 deletions

View File

@ -4,7 +4,7 @@ datafile=$(mktemp)
# We expect other Nagios checks to monitor for whether no queue # We expect other Nagios checks to monitor for whether no queue
# workers are running, so we give that condition a pass # workers are running, so we give that condition a pass
processes=$(pgrep -f '^python.* /home/zulip/deployments/current/manage.py process_queue') processes=$(pgrep -xf 'python.* /home/zulip/deployments/current/manage.py process_queue .*')
if [ -z "$processes" ]; then if [ -z "$processes" ]; then
echo "No workers running" echo "No workers running"
exit 0 exit 0

View File

@ -59,7 +59,7 @@ class zulip::profile::rabbitmq {
# running and exits if so. # running and exits if so.
exec { 'epmd': exec { 'epmd':
command => 'epmd -daemon', command => 'epmd -daemon',
unless => 'which pgrep && pgrep -f [e]pmd >/dev/null', unless => 'which pgrep && pgrep -x epmd >/dev/null',
require => Package[$erlang], require => Package[$erlang],
path => '/usr/bin/:/bin/', path => '/usr/bin/:/bin/',
} }

View File

@ -85,7 +85,7 @@ class zulip::supervisor {
# don't match. # don't match.
hasrestart => true, hasrestart => true,
# lint:ignore:140chars # lint:ignore:140chars
restart => "bash -c 'if pgrep -f supervisor[d] >/dev/null; then supervisorctl reread && supervisorctl update; else ${zulip::common::supervisor_start}; fi'", restart => "bash -c 'if pgrep -x supervisord >/dev/null; then supervisorctl reread && supervisorctl update; else ${zulip::common::supervisor_start}; fi'",
# lint:endignore # lint:endignore
} }
exec { 'supervisor-restart': exec { 'supervisor-restart':

View File

@ -1 +1 @@
* * * * * root /bin/bash -c '(pgrep -u nobody -f camo || /etc/init.d/camo restart) 2>&1 >>/var/log/camo/restart-log' * * * * * root /bin/bash -c '(pgrep -u nobody -F /var/run/camo.pid || /etc/init.d/camo restart) 2>&1 >>/var/log/camo/restart-log'

View File

@ -138,7 +138,7 @@ if action == "start" or args.less_graceful:
using_sso = subprocess.check_output(["./scripts/get-django-setting", "USING_APACHE_SSO"]) using_sso = subprocess.check_output(["./scripts/get-django-setting", "USING_APACHE_SSO"])
if using_sso.strip() == b"True": if using_sso.strip() == b"True":
logging.info("Restarting Apache WSGI process...") logging.info("Restarting Apache WSGI process...")
subprocess.check_call(["pkill", "-f", "apache2", "-u", "zulip"]) subprocess.check_call(["pkill", "-x", "apache2", "-u", "zulip"])
logging.info("Done!") logging.info("Done!")
print(OKGREEN + f"Zulip {action}ed successfully!" + ENDC) print(OKGREEN + f"Zulip {action}ed successfully!" + ENDC)