-
Notifications
You must be signed in to change notification settings - Fork 39
/
run.py
36 lines (30 loc) · 1.15 KB
/
run.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
from configobj import ConfigObj
import os
import socket
SERVICE_DIR = 'services/'
def checkport(host,port):
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
return sock.connect_ex((host, port))
def launchsvc(svc,host,port):
#Check if the service is running or not
addr = "localhost:{}".format(port)
resp = checkport(host, int(port))
if resp != 0:
print "Service {} not running, starting service at port {} on host {}".format(svc, port, host)
os.system('python '+ SERVICE_DIR + svc + '.py &')
else:
print "Service {} running at port {} on host {}".format(svc, port, host)
def walkthrough(section,obj):
if 'preload' in section:
services = section['preload'].split(' ')
for service in services:
launchsvc(service, obj[service]['host'], obj[service]['port'])
launchsvc(section.name, section['host'], section['port'])
def loadDependencies():
#Read the dependency file
config = ConfigObj('dependencies.ini')
#config.walk(walkthrough, obj=config)
for section in config:
walkthrough(config[section], config)
if __name__ == '__main__':
loadDependencies()