#!/usr/bin/python2 """ @author: Fabio Erculiani @contact: lxnay@sabayon.org @copyright: Fabio Erculiani @license: GPL-2 B{Entropy Package Manager Service}. """ import os import sys import time import signal import threading sys.path.insert(0,'/usr/lib/entropy/libraries') sys.path.insert(0,'/usr/lib/entropy/client') sys.path.insert(0,'../libraries') sys.path.insert(0,'../client') # disable pid management sys.argv.append("--no-pid-handling") do_ssl = False do_stdout_logging = True community_repo = False do_port = 1027 from entropy.i18n import _ from entropy.const import etpConst etpConst['community']['mode'] = community_repo etpConst['socket_service']['session_ttl'] = 300 from entropy.core.settings.base import SystemSettings SysSettings = SystemSettings() from entropy.tools import get_year, print_traceback from entropy.output import nocolor from text_tools import print_menu myopts = [ None, (0," ~ "+SysSettings['system']['name']+" ~ "+sys.argv[0]+" ~ ",1,'Repository Administration daemon - (C) %s' % (get_year(),) ), None, (0,_('Basic Options'),0,None), None, (1,'--help',2,_('this output')), (1,'--nocolor',1,_('disable colorized output')), None, (0,_('Application Options'),0,None), None, (1,'--ssl',2,_('enable SSL service too')), (1,'--nostdout',1,_('disable output to stdout, redirect to log file')), (1,'--community',1,_('this service hosts a community repository')), (1,'--port=N',1,_('specify listening port (SSL will be N+1)')), None, ] if "--nocolor" in sys.argv: nocolor() if "--help" in sys.argv: print_menu(myopts) raise SystemExit(1) if "--ssl" in sys.argv: do_ssl = True if "--nostdout" in sys.argv: do_stdout_logging = False if "--community" in sys.argv: community_repo = True if "--port" in sys.argv: idx = sys.argv.index("--port")+1 try: do_port = int(sys.argv[idx]) except (IndexError, ValueError,): pass from entropy.services.system.interfaces import Server as ServiceServer from entropy.services.system.executors import Base from entropy.services.system.commands import Repository from entropy.server.interfaces import Server from entropy.misc import ParallelTask def kill_threads(): for th in threading.enumerate(): if hasattr(th, 'kill'): th.kill() def term_myself(): os.kill(os.getpid(), signal.SIGTERM) def run_srv(s): try: s.go() except: print_traceback() raise finally: if s is not None: s.killall() kill_threads() term_myself() srv = ServiceServer( Server, do_ssl = do_ssl, stdout_logging = do_stdout_logging, external_cmd_classes = [Repository], external_executor_cmd_classes = [(Base,[],{},)], entropy_interface_kwargs = { 'community_repo': etpConst['community']['mode'] } ) srv.port = do_port thread_names = ["system_socket"] task = ParallelTask(run_srv, srv) task.setName(thread_names[0]) task.start() try: while task.isAlive(): time.sleep(2) finally: if srv is not None: srv.killall() kill_threads() term_myself()