1

I would like to start a python SimpleHTTPServer instance but I would like to give the ability to everyone to stop it (execute kill -1). It wouldn't be a big deal to solve but I don't have the access to the systems user/group config. Is this possible at all?

  • "everyone" on the Internet (have a page with a shutdown button), or on the local system (perhaps a socket that users on the system can write a kill command to, other end notices that and does the kill with permissions)? – thrig Mar 31 '17 at 13:55
  • do like apache does wiht apache2ctl - just write a simple program in some compiled language and use the setuid and setgid bits with a dedicated user that has minimal/no other rights. – ivanivan Mar 31 '17 at 22:32
0

If the server is running as a dedicated user then you could keep a copy of /bin/kill that's setuid to that user. This only works if the user isn't used for anything else, because a setuid kill binary allows sending a signal to any process running as that user. A setuid wrapper that checks the PID before killing isn't really doable: there's no way to examine running programs without a race condition.

The other way to approach this is to have a monitoring program that runs as the same user as the server, and is primed to kill the server, with a trigger condition that isn't bound to the user account. The monitoring program needs to be the parent of the server in order to be able to reliably kill it without risking a race condition. The trigger can be something like writing to a pipe. Proof-of-concept:

#!/bin/sh
SimpleHTTPServer &
server_pid=$!
read </var/lib/myserver/kill
kill "$server_pid"

To set this up:

mkdir /var/run/myserver
mkfifo -m 660 /var/run/myserver/kill
chown server-user /var/run/myserver/kill
chgrp server-killers /var/run/myserver/kill

To kill the server, any user in the server-killers group can run echo >/var/run/myserver/kill.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.