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.
This commit is contained in:
Alex Vandiver 2024-02-07 19:57:28 +00:00 committed by Tim Abbott
parent 20d90a6df6
commit 0115fa9c60
2 changed files with 10 additions and 2 deletions

View File

@ -25,6 +25,7 @@ from scripts.lib.zulip_tools import (
has_process_fts_updates, has_process_fts_updates,
overwrite_symlink, overwrite_symlink,
start_arg_parser, start_arg_parser,
su_to_zulip,
) )
action = "restart" action = "restart"
@ -41,7 +42,10 @@ args = parser.parse_args()
deploy_path = os.path.realpath(os.path.join(os.path.dirname(__file__), "..")) deploy_path = os.path.realpath(os.path.join(os.path.dirname(__file__), ".."))
os.chdir(deploy_path) 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'.") logging.error("Must be run as user 'zulip'.")
sys.exit(1) sys.exit(1)

View File

@ -18,12 +18,16 @@ from scripts.lib.zulip_tools import (
WARNING, WARNING,
has_application_server, has_application_server,
has_process_fts_updates, has_process_fts_updates,
su_to_zulip,
) )
deploy_path = os.path.realpath(os.path.join(os.path.dirname(__file__), "..")) deploy_path = os.path.realpath(os.path.join(os.path.dirname(__file__), ".."))
os.chdir(deploy_path) 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'.") logging.error("Must be run as user 'zulip'.")
sys.exit(1) sys.exit(1)