From 0115fa9c60c99f302242a760709c54812b70a689 Mon Sep 17 00:00:00 2001 From: Alex Vandiver Date: Wed, 7 Feb 2024 19:57:28 +0000 Subject: [PATCH] start-server/restart-server: Drop privileges if necessary. Rather than tell the user to re-run the command as `zulip` instead of `root`, do the privilege-dropping ourselves. --- scripts/restart-server | 6 +++++- scripts/stop-server | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/scripts/restart-server b/scripts/restart-server index 0b0a55cc2c..c7664aa027 100755 --- a/scripts/restart-server +++ b/scripts/restart-server @@ -25,6 +25,7 @@ from scripts.lib.zulip_tools import ( has_process_fts_updates, overwrite_symlink, start_arg_parser, + su_to_zulip, ) action = "restart" @@ -41,7 +42,10 @@ args = parser.parse_args() deploy_path = os.path.realpath(os.path.join(os.path.dirname(__file__), "..")) os.chdir(deploy_path) -if pwd.getpwuid(os.getuid()).pw_name != "zulip": +username = pwd.getpwuid(os.getuid()).pw_name +if username == "root": + su_to_zulip() +elif username != "zulip": logging.error("Must be run as user 'zulip'.") sys.exit(1) diff --git a/scripts/stop-server b/scripts/stop-server index 1a95b5d927..03f127758d 100755 --- a/scripts/stop-server +++ b/scripts/stop-server @@ -18,12 +18,16 @@ from scripts.lib.zulip_tools import ( WARNING, has_application_server, has_process_fts_updates, + su_to_zulip, ) deploy_path = os.path.realpath(os.path.join(os.path.dirname(__file__), "..")) os.chdir(deploy_path) -if pwd.getpwuid(os.getuid()).pw_name != "zulip": +username = pwd.getpwuid(os.getuid()).pw_name +if username == "root": + su_to_zulip() +elif username != "zulip": logging.error("Must be run as user 'zulip'.") sys.exit(1)