#!/usr/bin/env python12# Ensure that system-wide daemons are running.3# If <service> is not running, do "service <service> restart".4# We do NOT just do "service <service> start" since that does5# not work (it's just an observerable fact).6#7# Put this in a crontab, e.g.,8#9# * * * * * /home/salvus/forever.py rethinkdb >> /home/salvus/.forever_rethinkdb.log 2>> /home/salvus/.forever_rethinkdb.err10#1112import os, sys, time1314SERVICES = sys.argv[1:]15if len(SERVICES) == 0 or len([x for x in SERVICES if x.startswith('-')]):16sys.stderr.write("usage: %s <service> <service> ...\n"%sys.argv[0])17sys.exit(1)1819def is_running(service):20return bool(os.popen("pidof %s"%service).read())2122def test(service):23if not is_running(service):24print("%s: %s not running so restarting"%(service, time.asctime()))25os.system("sudo service %s restart"%service)2627for service in SERVICES:28test(service)29303132