File start-cyclops-slaves of Package gaia2
#!/usr/bin/python3
#
# Copyright (C) 2010 MTG, Universitat Pompeu Fabra
#
# Init file for cyclopsslaves
#
# description: cyclops slave daemon
#
import sys, yaml, subprocess, pwd, os
DAEMON='/usr/bin/cyclops'
CONFIG_FILE='/etc/cyclops/master.yaml'
USER='cyclops'
def usage():
print('This script should be run by activating the systemd cyclops-slaves service')
def read_config():
# read config file and get list of slaves
try:
slaves = yaml.load(open(CONFIG_FILE).read())['slaves']
except:
print('Could not read slave configuration from config file:', CONFIG_FILE)
sys.exit(1)
return slaves
def start_daemon(port):
p = subprocess.Popen([ DAEMON, '-p', str(port) ])
return p.pid
def start_slaves():
slaves = read_config()
# start slaves one by one
pids = []
GD
snum = 1
for sc in slaves:
if sc['host'] in [ 'localhost', '127.0.0.1' ]:
print("Starting Cyclops slave %d on port %d" % (snum, sc['port']))
pids += [ start_daemon(sc['port']) ]
snum += 1
if __name__ == '__main__':
if len(sys.argv) < 2:
usage()
sys.exit(1)
cmd = sys.argv[1]
if cmd == 'start':
start_slaves()
else:
usage()