def rpc_run(self, pcode, user, visitor): uid = 6858 userdir = '/tmp/' + user try: os.mkdir(userdir) except OSError: pass os.chmod(userdir, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR) os.chown(userdir, uid, uid) (sa, sb) = socket.socketpair(socket.AF_UNIX, socket.SOCK_STREAM, 0) pid = os.fork() if pid == 0: if os.fork() <= 0: sa.close() ct = readconf.read_conf() ProfileAPIServer(user, visitor, pcode, ct).run_sock(sb) sys.exit(0) else: sys.exit(0) sb.close() os.waitpid(pid, 0) sandbox = sandboxlib.Sandbox(userdir, uid, '/tmp/lockfile') with rpclib.RpcClient(sa) as profile_api_client: return sandbox.run(lambda: run_profile(pcode, profile_api_client))
def shutdown(k=None): ct = readconf.read_conf() if k == None: for k in ct.svcs(): c = lxc.Container(k) c.stop() else: c = lxc.Container(k) c.stop()
def ps(k=None): ct = readconf.read_conf() if k == None: for k in sorted(ct.svcs()): c = lxc.Container(k) print(info(c)) else: c = lxc.Container(k) print(info(c))
def run_profile(user): try: pcode = user.profile pcode = pcode.replace('\r\n', '\n') host = readconf.read_conf().lookup_host('profile') with rpclib.client_connect(host) as c: return c.call('run', pcode=pcode, user= user.username, visitor=g.user.person.username) except Exception as e: traceback.print_exc() return 'Exception: ' + str(e)
def start(k): ct = readconf.read_conf(d="/home/student/") if k == "main": (rfd, wfd) = socket.socketpair(socket.AF_UNIX, socket.SOCK_STREAM, 0) sock = start_server(k, ct.lookup("main", "port")) conf = ct.conf(k) svcs = conf.http_svcs() sendnsvc(len(svcs), wfd) sendct(wfd, svcs, ct, 'url', 'string') sendct(wfd, svcs, ct, 'lxcbr', 'int') sendct(wfd, svcs, ct, 'port', 'int') p = clone(conf, rfd, sock) else: p = clone(ct.conf(k)) return p
def clean(k=None): shutdown(k) ct = readconf.read_conf() if k == None: for k in ct.svcs(): c = lxc.Container(k) c.shutdown(timeout=0) c.destroy() for k in lxc.list_containers(): c = lxc.Container(k) c.shutdown(timeout=0) c.destroy() c = lxc.Container(BASE) c.shutdown(timeout=0) c.destroy() else: c = lxc.Container(k) c.destroy()
def boot(k=None): ct = readconf.read_conf() # check for link dups svcs_on_link = collections.defaultdict(list) for s in ct.svcs(): link = ct.lookup(s, 'lxcbr') if link is None: raise Exception("Missing lxcbr link for container %s" % s) if link not in [str(i) for i in range(0, 10)]: raise Exception("Unknown lxcbr link %s for container %s" % (link, s)) svcs_on_link[link].append(s) for link in svcs_on_link: if len(svcs_on_link[link]) > 1: raise Exception("More than one container on lxcbr%s: %s" % (link, svcs_on_link[link])) if k == None: for k in ct.svcs(): c = Container(ct.conf(k), k, ct.svcs(), ct) c.zooksvc(k) else: c = Container(ct.conf(k), k, ct.svcs(), ct) c.zooksvc(k)
def main(argv): if len(argv) == 0: print ("""\nUsage: python3 -m adapter config-file.ini ( stop | daemon ) """ + adapter_app +""", version """ + adapter_version +""" config-file Configuration file, see mcfeedadapter_example.conf for examples. action Optional, one of the following: stop Stop running adapter daemon Start adapter as daemon """) return 0 print (adapter_app + """, version """ + adapter_version + "\n") print ("") args=readconf.parse_argv(argv) if cfg.action is not None: if cfg.action == 'daemon': utils.become_daemon(); if not readconf.read_conf(args): return 1; if not initialize_outputs(): close_outputs() return 1; current_pid=utils.file_read(cfg.pid_file) if cfg.action is not None: if (cfg.action == 'stop') or (cfg.action == 'status'): if current_pid is None: print("Adapter is not running\n") return 0 process_id=int(current_pid) print("Adapter found, PID " + str(process_id)) if cfg.action == 'stop': utils.remove_file(cfg.pid_file) while utils.is_process_running(process_id): time.sleep(0.05) print("Adapter stopped\n") return 0 if current_pid is not None: utils.print_error("Adapter for this feed is already running") return 1 utils.file_write(cfg.pid_file,utils.get_pid()) signal.signal(signal.SIGINT,term_signal_handler) signal.signal(signal.SIGTERM,term_signal_handler) current_pid=utils.file_read(cfg.pid_file) utils.log_write("Adapter started, PID: " + str(current_pid)) while current_pid is not None: iteration_result=adapter_iteration() if cfg.action is not None: if cfg.action == 'term': utils.remove_file(cfg.pid_file) current_pid = None if current_pid is not None: if not iteration_result[0]: utils.print_error("Adapter encountered error when processing feed records and will be stopped") utils.remove_file(cfg.pid_file) return 1 if not iteration_result[1]: time.sleep(0.1) current_pid=utils.file_read(cfg.pid_file) close_outputs() utils.log_write("Adapter stopped")
def set_caller_ip(self, ip): self.caller = None conf = readconf.read_conf() for svcname in conf.svcs(): if ip == conf.lookup_host(svcname)[0]: self.caller = svcname
""" # Build paths inside the project like this: os.path.join(BASE_DIR, ...) import os BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) ############################################################################################################### ############# adicionado para ler arquivo externo com configuraçãoes sensíveis e sigilosas ################ ############################################################################################################### # definir nome do arquivo para settings.conf SETTINGS_EXTRA = 'settings.conf' import readconf readconf.read_conf(os.path.join(os.path.dirname(os.path.dirname(__file__)), SETTINGS_EXTRA)) ############################################################################################################### # Quick-start development settings - unsuitable for production # See https://docs.djangoproject.com/en/1.8/howto/deployment/checklist/ # SECURITY WARNING: keep the secret key used in production secret! # SECRET_KEY = '2mzi2-0yypz*k^a0lo)q*0rb(&xisqr8infd(&e97#x1p(&p%+' SECRET_KEY = os.environ.get('SECRET_KEY') # SECURITY WARNING: don't run with debug turned on in production! # DEBUG = True DEBUG = os.environ.get('DEBUG')
from debug import * from zoodb import * import rpclib sys.path.append(os.getcwd()) import readconf host = readconf.read_conf().lookup_host('auth') def login(username, password): with rpclib.client_connect(host) as c: return c.call('login', username=username, password=password) def register(username, password): with rpclib.client_connect(host) as c: return c.call('register', username=username, password=password) def check_token(username, token): with rpclib.client_connect(host) as c: return c.call('check_token', username=username, token=token)
def echo(): host = readconf.read_conf().lookup_host('echo') with rpclib.client_connect(host) as c: ret = c.call('echo', s=request.args.get('s', '')) return render_template('echo.html', s=ret)
from debug import * from zoodb import * import rpclib sys.path.append(os.getcwd()) import readconf host = readconf.read_conf().lookup_host('bank') def init(username): with rpclib.client_connect(host) as c: return c.call('init', username=username) def transfer(sender, recipient, zoobars, token): with rpclib.client_connect(host) as c: return c.call('transfer', sender=sender, recipient=recipient, zoobars=zoobars, token=token) def balance(username): with rpclib.client_connect(host) as c: return c.call('balance', username=username) def get_log(username): with rpclib.client_connect(host) as c: