I am trying to write a python script which shows me the services which are running on my server.
Don't do that. That's exactly what a process manager like
systemd is for. Using
systemd, a simple unit file for mongo might look something like:
Description=High-performance, schema-free document-oriented database
ExecStart=/usr/bin/mongod $OPTIONS run
If you want this to restart automatically when it fails, you can add to the
If you are unlucky enough to be working on a system without a modern
process manager, you can use a tool like supervisor to achieve the
But for real, if your application keeps crashing, you are much better
off trying to find the source of the problem. Mongodb logs information to wherever
logpath in your
/etc/mongod.conf file points (
/var/log/mongodb/mongodb.log on my system), and this is probably the first place to look for problems.
Other applications provide similar diagnostic information that can help find the root cause of the crashes.