Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download
Views: 39551
1
#!/usr/bin/env python
2
3
# Ensure that system-wide daemons are running.
4
# If <service> is not running, do "service <service> restart".
5
# We do NOT just do "service <service> start" since that does
6
# not work (it's just an observerable fact).
7
#
8
# Put this in a crontab, e.g.,
9
#
10
# * * * * * /home/salvus/forever.py rethinkdb >> /home/salvus/.forever_rethinkdb.log 2>> /home/salvus/.forever_rethinkdb.err
11
#
12
13
import os, sys, time
14
15
SERVICES = sys.argv[1:]
16
if len(SERVICES) == 0 or len([x for x in SERVICES if x.startswith('-')]):
17
sys.stderr.write("usage: %s <service> <service> ...\n"%sys.argv[0])
18
sys.exit(1)
19
20
def is_running(service):
21
return bool(os.popen("pidof %s"%service).read())
22
23
def test(service):
24
if not is_running(service):
25
print("%s: %s not running so restarting"%(service, time.asctime()))
26
os.system("sudo service %s restart"%service)
27
28
for service in SERVICES:
29
test(service)
30
31
32