Exemplo n.º 1
0
    def do_start(self):
        opts = self.optparser.parse_args()[0]
        self.__dict__.update(vars(opts))

        util.init_logging(self.log_file, self.verbose)

        if self.__dict__.get('set_repository'):
            print '-r|--set-repository no more works, cause updates are controlled from Scalr'
            sys.exit(0)
        if self.__dict__.get('get_system_id'):
            try:
                print self.api.get_system_id()
                sys.exit()
            except update_api.NoSystemUUID:
                print "system-id not detected"
                sys.exit(1)
        elif self.__dict__.get('make_status_file'):
            if os.path.exists(self.api.status_file):
                os.unlink(self.api.status_file)
            self.api.bootstrap(dry_run=True)
            if self.__dict__.get('downgrades_disabled'):
                self.api.downgrades_enabled = False
            self.api.store()
            print 'saved status file: {0}'.format(self.api.status_file)
            sys.exit()

        if self.daemonize:
            util.daemonize()
        if not linux.os.windows_family:
            signal.signal(signal.SIGHUP, self.onSIGHUP)
            signal.signal(signal.SIGTERM, self.onSIGTERM)

        LOG.info('Starting UpdateClient (pid: %s)', os.getpid())
        self._check_singleton()
        if linux.os.windows_family:
            try:
                wintool.wait_boot()
            except wintool.RebootExpected:
                LOG.info('Waiting for interruption...')
                time.sleep(600)
        try:
            self._write_pid_file()
            self._start_api()
            # Starting API before bootstrap is important for situation, when
            # Scalarizr daemon is started in a parallel and required to know that
            # update is in-progress

            self.running = True
            # It should be here, cause self.api.bootstrap() on Windows
            # leads to updclient restart and self.stop(), that is called for this
            # checks for self.running is True to perform graceful shutdown

            self.api.bootstrap()
        except:
            self.do_stop()
            LOG.exception('Detailed exception information below:')
            sys.exit(1)
Exemplo n.º 2
0
def _pre_main():
    optparser = bus.optparser = OptionParser()
    optparser.add_option('-v', '--version', dest='version', action='store_true',
            help='Show version information')
    optparser.add_option('-c', '--etc-path', dest='etc_path',
            help='Configuration directory path')
    optparser.add_option('-l', dest='debug', action='store_true', default=False,
            help='Enable debug log')
    optparser.add_option('-n', '--configure', dest='configure', action="store_true", default=False, 
            help="Configure Scalarizr in the interactive mode by default. " 
            + "Use '-y -o' to configure Scalarizr non-interactively")
    optparser.add_option("-k", "--gen-key", dest="gen_key", action="store_true", default=False,
            help='Generate crypto key')
    optparser.add_option('-t', dest='validate_cnf', action='store_true', default=False,
            help='Validate configuration')
    optparser.add_option('-m', '--import', dest="import_server", action="store_true", default=False, 
            help='Import service into Scalr')
    optparser.add_option('-y', dest="yesall", action="store_true", default=False,
            help='Answer "yes" to all questions')
    optparser.add_option('-o', dest='cnf', action='append',
            help='Runtime .ini option key=value')

    if linux.os['family'] != 'Windows':
        optparser.add_option("-z", dest="daemonize", action="store_true", default=False,
                                           help='Daemonize process')
    else:
        optparser.add_option("--install-win-services", dest="install_win_services", action="store_true",
                             default=False, help='Install scalarizr as windows service')
        optparser.add_option("--uninstall-win-services", dest="uninstall_win_services", action="store_true",
                             default=False, help='Uninstall scalarizr windows service')

    if ('cloud-location=' in sys.argv or 'region=' in sys.argv) and 'platform=ec2' in sys.argv:
        region = urllib2.urlopen('http://169.254.169.254/latest/meta-data/placement/availability-zone').read().strip()[:-1]
        try:
            sys.argv[sys.argv.index('region=')] += region
        except ValueError:
            sys.argv += ['-o', 'region=' + region]        
    
    optparser.parse_args()
    
    # Daemonize process
    if linux.os['family'] != 'Windows' and optparser.values.daemonize:
        daemonize()

    if optparser.values.version:
        # Report scalarizr version
        print 'Scalarizr %s' % __version__
        sys.exit()

    elif optparser.values.gen_key:
        # Generate key-pair
        do_keygen()
        sys.exit()
Exemplo n.º 3
0
    def do_start(self):
        opts = self.optparser.parse_args()[0]
        self.__dict__.update(vars(opts))

        util.init_logging(self.log_file, self.verbose)
        self._wait_network()

        if self.__dict__.get('set_repository'):
            print '-r|--set-repository no more works, cause updates are controlled from Scalr'
            sys.exit(0)
        if self.__dict__.get('get_system_id'):
            try:
                print self.api.get_system_id()
                sys.exit()
            except update_api.NoSystemUUID:
                print "system-id not detected"
                sys.exit(1)
        elif self.__dict__.get('make_status_file'):
            if os.path.exists(self.api.status_file):
                os.unlink(self.api.status_file)
            self.api.bootstrap(dry_run=True)
            if self.__dict__.get('downgrades_disabled'):
                self.api.downgrades_enabled = False
            self.api.store()
            print 'saved status file: {0}'.format(self.api.status_file)
            sys.exit() 

        if self.daemonize:
            util.daemonize()
        if not linux.os.windows_family:
            signal.signal(signal.SIGHUP, self.onSIGHUP)
            signal.signal(signal.SIGTERM, self.onSIGTERM)

        LOG.info('Starting UpdateClient (pid: %s)', os.getpid())
        self._check_singleton()
        try:
            self._write_pid_file()
            self._start_api()  
            # Starting API before bootstrap is important for situation, when 
            # Scalarizr daemon is started in a parallel and required to know that 
            # update is in-progress

            self.running = True  
            # It should be here, cause self.api.bootstrap() on Windows
            # leads to updclient restart and self.stop(), that is called for this  
            # checks for self.running is True to perform graceful shutdown

            self.api.bootstrap()
        except:
            self.do_stop()
            LOG.exception('Detailed exception information below:')
            sys.exit(1)
Exemplo n.º 4
0
        if ('cloud-location=' in sys.argv
                or 'region=' in sys.argv) and 'platform=ec2' in sys.argv:
            region = urllib2.urlopen(
                'http://169.254.169.254/latest/meta-data/placement/availability-zone'
            ).read().strip()[:-1]
            try:
                sys.argv[sys.argv.index('region=')] += region
            except ValueError:
                sys.argv += ['-o', 'region=' + region]

        optparser.parse_args()

        # Daemonize process
        if optparser.values.daemonize:
            daemonize()

        if optparser.values.version:
            # Report scalarizr version
            print 'Scalarizr %s' % __version__
            sys.exit()

        elif optparser.values.gen_key:
            # Generate key-pair
            do_keygen()
            sys.exit()

        logger.debug("Initialize scalarizr...")
        _init()

        # Starting scalarizr daemon initialization
Exemplo n.º 5
0
def _pre_main():
    optparser = bus.optparser = OptionParser()
    optparser.add_option('-v',
                         '--version',
                         dest='version',
                         action='store_true',
                         help='Show version information')
    optparser.add_option('-c',
                         '--etc-path',
                         dest='etc_path',
                         help='Configuration directory path')
    optparser.add_option('-l',
                         dest='debug',
                         action='store_true',
                         default=False,
                         help='Enable debug log')
    optparser.add_option(
        '-n',
        '--configure',
        dest='configure',
        action="store_true",
        default=False,
        help="Configure Scalarizr in the interactive mode by default. " +
        "Use '-y -o' to configure Scalarizr non-interactively")
    optparser.add_option("-k",
                         "--gen-key",
                         dest="gen_key",
                         action="store_true",
                         default=False,
                         help='Generate crypto key')
    optparser.add_option('-t',
                         dest='validate_cnf',
                         action='store_true',
                         default=False,
                         help='Validate configuration')
    optparser.add_option('-m',
                         '--import',
                         dest="import_server",
                         action="store_true",
                         default=False,
                         help='Import service into Scalr')
    optparser.add_option('-y',
                         dest="yesall",
                         action="store_true",
                         default=False,
                         help='Answer "yes" to all questions')
    optparser.add_option('-o',
                         dest='cnf',
                         action='append',
                         help='Runtime .ini option key=value')

    if linux.os['family'] != 'Windows':
        optparser.add_option("-z",
                             dest="daemonize",
                             action="store_true",
                             default=False,
                             help='Daemonize process')
    else:
        optparser.add_option("--install-win-services",
                             dest="install_win_services",
                             action="store_true",
                             default=False,
                             help='Install scalarizr as windows service')
        optparser.add_option("--uninstall-win-services",
                             dest="uninstall_win_services",
                             action="store_true",
                             default=False,
                             help='Uninstall scalarizr windows service')

    if ('cloud-location=' in sys.argv
            or 'region=' in sys.argv) and 'platform=ec2' in sys.argv:
        region = urllib2.urlopen(
            'http://169.254.169.254/latest/meta-data/placement/availability-zone'
        ).read().strip()[:-1]
        try:
            sys.argv[sys.argv.index('region=')] += region
        except ValueError:
            sys.argv += ['-o', 'region=' + region]

    optparser.parse_args()

    # Daemonize process
    if linux.os['family'] != 'Windows' and optparser.values.daemonize:
        daemonize()

    if optparser.values.version:
        # Report scalarizr version
        print 'Scalarizr %s' % __version__
        sys.exit()

    elif optparser.values.gen_key:
        # Generate key-pair
        do_keygen()
        sys.exit()
Exemplo n.º 6
0
 def reboot(self):
     if os.fork():
         return
     util.daemonize()
     system2(('reboot', ))
     exit(0)
Exemplo n.º 7
0
		optparser.add_option('-o', dest='cnf', action='append',
				help='Runtime .ini option key=value')
		
		if ('cloud-location=' in sys.argv or 'region=' in sys.argv) and 'platform=ec2' in sys.argv:
			region = urllib2.urlopen('http://169.254.169.254/latest/meta-data/placement/availability-zone').read().strip()[:-1]
			try:
				sys.argv[sys.argv.index('region=')] += region
			except ValueError:
				sys.argv += ['-o', 'region=' + region]		
		
		optparser.parse_args()

		
		# Daemonize process
		if optparser.values.daemonize:
			daemonize()

		if optparser.values.version:
			# Report scalarizr version
			print 'Scalarizr %s' % __version__
			sys.exit()

		elif optparser.values.gen_key:
			# Generate key-pair
			do_keygen()
			sys.exit()

		logger.debug("Initialize scalarizr...")
		_init()

		# Starting scalarizr daemon initialization
Exemplo n.º 8
0
 def reboot(self):
     if os.fork():
         return
     util.daemonize()
     system2(('reboot',))
     exit(0)
Exemplo n.º 9
0
    def do_start(self):
        opts = self.optparser.parse_args()[0]
        self.__dict__.update(vars(opts))

        util.init_logging(self.log_file, self.verbose)

        if self.__dict__.get('set_repository'):
            print '-r|--set-repository no more works, cause updates are controlled from Scalr'
            sys.exit(0)
        if self.__dict__.get('get_system_id'):
            try:
                print self.api.get_system_id()
                sys.exit()
            except update_api.NoSystemUUID:
                print "system-id not detected"
                sys.exit(1)
        elif self.__dict__.get('make_status_file'):
            if os.path.exists(self.api.status_file):
                os.unlink(self.api.status_file)
            self.api.bootstrap(dry_run=True)
            if self.__dict__.get('downgrades_disabled'):
                self.api.downgrades_enabled = False
            self.api.store()
            print 'saved status file: {0}'.format(self.api.status_file)
            sys.exit()

        if self.daemonize:
            util.daemonize()
        if not linux.os.windows_family:
            signal.signal(signal.SIGHUP, self.onSIGHUP)
            signal.signal(signal.SIGTERM, self.onSIGTERM)

        LOG.info('Starting UpdateClient (pid: %s)', os.getpid())
        self._check_singleton()
        if linux.os.windows_family:
            try:
                wintool.wait_boot()
            except wintool.RebootExpected:
                LOG.info('Waiting for interruption...')
                time.sleep(600)
            # [ SCALARIZR-2044 ]
            self._fix_cache_dir_location()

        try:
            self._write_pid_file()

            # Run Scalr-Init routines
            agent.scalrinit.app.main_start()

            self._start_api(
            )  # Start API before bootstrap is important for situation, when
            # Scalarizr starting in a parallel and call ScalrUpdClient to know whether
            # update is in-progress

            self.running = True  # It should be here, cause self.api.bootstrap() on Windows
            # leads to restart and self.stop() will be called before do_start() finishes

            self.api.bootstrap()
        except:
            exc_info = sys.exc_info()
            self.do_stop()
            if not isinstance(exc_info[1], KeyboardInterrupt):
                LOG.exception('Detailed exception information below:')
            sys.exit(1)