Closed dvaerum closed 8 years ago
Hey, thanks for the code and idea!
I played around with just implementing the psutil pid_exists function directly, but messing around with platform detection and different configurations seemed like a bit too much work, so I've added psutil as a dependency. On the plus side, I can probably simplify the hdd usage and mem calculations to work more broadly across platforms.
I added some code that might do what you are referring to in your comments (d71c279ae747ac64a3d699691ba74225c21b19a6). It checks that the UID of the process is the same as the current user, and then checks that the command line argument of the process includes both python
and pyrt
. I think this might be sufficient enough?
Note that the PR as it stands will attempt to kill process ID 1 instead of the the pyRT process since it returns True, so I modified it to also return the correct PID.
I've merged it with the testing branch until I'm happy that it's working, need to work out a way to make it crash now :)
I have look over the code, and yes I thing that will be sufficient enough.
The only other thing I can thing of, is to let pyrt connect to a unix socket at upstart and if it can connect the service is running and pyrt exit, if it not connect the service is not and pyrt starts and create the unit socket.
You can also just create a service for SysV or systemd to handle it :)
In regard to finding a way to crash the program, if it is just for testing this code just terminal pyrt with kill -9 PID
One last thing, pyrt is also depending on the package requests
Hmm the unix socket thing could be pretty simple to implement, could just do it with one of the many existing sockets in .sockets
. Could just try opening a websocket on rpc0.interface
and if pyRT isn't running it would raise an error.
However, I think the psutil approach is sufficient for determining whether pyRT is running.
systemd might be nice to implement, though my current distro (Gentoo) uses OpenRC, and I think Ubuntu uses Upstart, no idea about OS X which it seems some people use for PyRT (at least, someone did a while back when I was adding memory information).
Might be merging testing
into master
shortly, since I think everything seems to be working OK, so that will close this pull request.
you will the need python package psutil