docs: def main():
      """ Main function called from dynamic-dynamodb """
      try:
          if get_global_option('show_config'):
              print json.dumps(config.get_configuration(), indent=2)
          elif get_global_option('daemon'):
              daemon = DynamicDynamoDBDaemon(
                  '{0}/dynamic-dynamodb.{1}.pid'.format(
                      get_global_option('pid_file_dir'),
                      get_global_option('instance')))
  
              if get_global_option('daemon') == 'start':
                  logger.debug('Starting daemon')
                  try:
                      daemon.start()
                      logger.info('Daemon started')
                  except IOError as error:
                      logger.error('Could not create pid file: {0}'.format(error))
                      logger.error('Daemon not started')
              elif get_global_option('daemon') == 'stop':
                  logger.debug('Stopping daemon')
                  daemon.stop()
                  logger.info('Daemon stopped')
                  sys.exit(0)
  
              elif get_global_option('daemon') == 'restart':
                  logger.debug('Restarting daemon')
                  daemon.restart()
                  logger.info('Daemon restarted')
  
              elif get_global_option('daemon') in ['foreground', 'fg']:
                  logger.debug('Starting daemon in foreground')
                  daemon.run()
                  logger.info('Daemon started in foreground')
  
              else:
                  print(
                      'Valid options for --daemon are start, '
                      'stop, restart, and foreground')
                  sys.exit(1)
          else:
              if get_global_option('run_once'):
                  execute()
              else:
                  while True:
                      execute()
  
      except Exception as error:
          logger.exception(error)