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?
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