'Handles the \'daemon\' CLI command.
Fires events:
* manager.daemon.started
* manager.daemon.completed
:param options: argparse options'

def daemon_command(self, options):

    if (options.action == u'start'):
        if self.is_daemon:
            log.error(u'Daemon    already    running    for    this    config.')
            return
        elif self.task_queue.is_alive():
            log.error(u'Non-daemon    execution    of    FlexGet    is    running.    Cannot    start    daemon    until    it    is    finished.')
            return
        if options.daemonize:
            self.daemonize()
        if options.autoreload_config:
            self.autoreload_config = True
        try:
            signal.signal(signal.SIGTERM, self._handle_sigterm)
        except ValueError as e:
            log.debug((u'Error    registering    sigterm    handler:    %s' % e))
        self.is_daemon = True
        fire_event(u'manager.daemon.started', self)
        self.task_queue.start()
        self.ipc_server.start()
        self.task_queue.wait()
        fire_event(u'manager.daemon.completed', self)
    elif (options.action in [u'stop', u'reload-config', u'status']):
        if (not self.is_daemon):
            log.error(u'There    does    not    appear    to    be    a    daemon    running.')
            return
        if (options.action == u'status'):
            log.info((u'Daemon    running.    (PID:    %s)' % os.getpid()))
        elif (options.action == u'stop'):
            tasks = (u'all    queued    tasks    (if    any)    have' if options.wait else u'currently    running    task    (if    any)    has')
            log.info((u'Daemon    shutdown    requested.    Shutdown    will    commence    when    %s    finished    executing.' % tasks))
            self.shutdown(options.wait)
        elif (options.action == u'reload-config'):
            log.info(u'Reloading    config    from    disk.')
            try:
                self.load_config()
            except ValueError as e:
                log.error((u'Error    loading    config:    %s' % e.args[0]))
            else:
                log.info(u'Config    successfully    reloaded    from    disk.')
