예제 #1
0
    def _configure_restart(self, ctx):
        if SA_RESTARTABLE not in self.get_sa_api_flags():
            return
        if self.launcher.restart_strategy:
            try:
                cls = get_strategy_by_name(self.launcher.restart_strategy)
                kwargs = copy.deepcopy(self.launcher.restart)
                # [restart] section has the kwargs for the strategy initializer
                # and the 'strategy' which is not one, let's pop it
                kwargs.pop('strategy')
                strategy = cls(**kwargs)
                ctx.sa.use_alternate_restart_strategy(strategy)

            except KeyError:
                _logger.warning(
                    _('Unknown restart strategy: %s',
                      (self.launcher.restart_strategy)))
                _logger.warning(
                    _('Using automatically detected restart strategy'))
                try:
                    strategy = detect_restart_strategy()
                except LookupError as exc:
                    _logger.warning(exc)
                    _logger.warning(_('Automatic restart disabled!'))
                    strategy = None
        else:
            strategy = detect_restart_strategy()
        if strategy:
            # gluing the command with pluses b/c the middle part
            # (launcher path) is optional
            snap_name = os.getenv('SNAP_NAME')
            if snap_name:
                # NOTE: This implies that any snap wishing to include a
                # Checkbox snap to be autostarted creates a snapcraft
                # app called "checkbox-cli"
                respawn_cmd = '/snap/bin/{}.checkbox-cli'.format(snap_name)
            else:
                respawn_cmd = sys.argv[0]  # entry-point to checkbox
            respawn_cmd += " launcher "
            if ctx.args.launcher:
                respawn_cmd += os.path.abspath(ctx.args.launcher) + ' '
            respawn_cmd += '--resume {}'  # interpolate with session_id
            ctx.sa.configure_application_restart(
                lambda session_id: [respawn_cmd.format(session_id)])
예제 #2
0
 def _configure_restart(self):
     strategy = detect_restart_strategy()
     snap_name = os.getenv('SNAP_NAME')
     if snap_name:
         # NOTE: This implies that any snap wishing to include a
         # Checkbox snap to be autostarted creates a snapcraft
         # app called "checkbox-cli"
         respawn_cmd = '/snap/bin/{}.checkbox-cli'.format(snap_name)
     else:
         respawn_cmd = sys.argv[0]  # entry-point to checkbox
     respawn_cmd += ' --resume {}'  # interpolate with session_id
     self.sa.configure_application_restart(
         lambda session_id: [respawn_cmd.format(session_id)])