Ejemplo n.º 1
0
 # Get command
 args = list(sys.argv)
 if '-d' in args:
     should_daemonize = True
     args.remove('-d')
 else:
     should_daemonize = False
 action = args[1] if len(args) > 1 else None
 actions = ('start', 'restart', 'stop', 'dump', 'update')
 if action not in actions:
     _err('Invalid action requested. Possible actions are %s.' % ', '.join(actions))
     sys.exit(1)
 # Check user
 user_name = os.environ['USER']
 if os.environ['USER'] != USER:
     system_utils.run_as(USER)
 # Daemonize
 if should_daemonize:
     wd = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
     daemonize(redirect_to=LOG_PATH, rundir=wd)
     sys.path.append(wd)
 # Write initial info in log
 _log('Started on %s by user %s.' % (now.strftime('%Y-%m-%d %H:%M:%S'), user_name))
 # Dump db
 if action in ('dump', 'update'):
     _log('\n---- Dumping database ----')
     db_path = '%s/db.sqlite3' % BASE_DIR
     dump_cmd = None
     if os.path.exists(CONF_OVERRIDE):
         conf = imp.load_source('conf', CONF_OVERRIDE)
         if hasattr(conf, 'DATABASES') and conf.DATABASES.get('default'):
Ejemplo n.º 2
0
 args = list(sys.argv)
 if '-d' in args:
     should_daemonize = True
     args.remove('-d')
 else:
     should_daemonize = False
 action = args[1] if len(args) > 1 else None
 actions = ('start', 'restart', 'stop', 'dump', 'update')
 if action not in actions:
     _err('Invalid action requested. Possible actions are %s.' %
          ', '.join(actions))
     sys.exit(1)
 # Check user
 user_name = os.environ['USER']
 if os.environ['USER'] != USER:
     system_utils.run_as(USER)
 # Daemonize
 if should_daemonize:
     wd = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
     daemonize(redirect_to=LOG_PATH, rundir=wd)
     sys.path.append(wd)
 # Write initial info in log
 _log('Started on %s by user %s.' %
      (now.strftime('%Y-%m-%d %H:%M:%S'), user_name))
 # Dump db
 if action in ('dump', 'update'):
     _log('\n---- Dumping database ----')
     db_path = '%s/db.sqlite3' % BASE_DIR
     dump_cmd = None
     if os.path.exists(CONF_OVERRIDE):
         conf = imp.load_source('conf', CONF_OVERRIDE)
Ejemplo n.º 3
0
            self.execute(['/usr/bin/mpc', 'shuffle'])
        elif key == 'KEY_MODE':
            self.play_sound('shutdown')
            self.execute(['sudo', 'shutdown', '-h', 'now'])
            lirc.deinit()
            sys.exit(0)
        elif key == 'KEY_CHANNELDOWN':
            i = self.playlist_index - 1
            if i >= 0:
                self.load_playlist(i)
        elif key == 'KEY_CHANNELUP':
            i = self.playlist_index + 1
            if i <= 9:
                self.load_playlist(i)
        elif key in ('KEY_0', 'KEY_1', 'KEY_2', 'KEY_3', 'KEY_4', 'KEY_5', 'KEY_6', 'KEY_7', 'KEY_8', 'KEY_9'):
            self.load_playlist(int(key[4]))
        else:
            logger.info('Received unbinded key: %s', key)


if __name__ == '__main__':
    user = subprocess.getoutput('whoami')
    if user != USER:
        # switch from root to requested user
        print('Using user %s.' % USER)
        from django_web_utils.system_utils import run_as
        run_as(USER)

    daemon = MopidyController(sys.argv)
    daemon.start()