diff --git a/agent.py b/agent.py index 3001b91a50..9b7447d6e5 100755 --- a/agent.py +++ b/agent.py @@ -77,6 +77,7 @@ def _handle_sigusr1(self, signum, frame): self._handle_sigterm(signum, frame) self._do_restart() + @classmethod def info(self, verbose=None): logging.getLogger().setLevel(logging.ERROR) return CollectorStatus.print_latest_status(verbose=verbose) @@ -212,12 +213,15 @@ def main(): autorestart = agentConfig.get('autorestart', False) hostname = get_hostname(agentConfig) - COMMANDS = [ + COMMANDS_AGENT = [ 'start', 'stop', 'restart', - 'foreground', 'status', + 'foreground', + ] + + COMMANDS_NO_AGENT = [ 'info', 'check', 'configcheck', @@ -225,6 +229,8 @@ def main(): 'flare', ] + COMMANDS = COMMANDS_AGENT + COMMANDS_NO_AGENT + if len(args) < 1: sys.stderr.write("Usage: %s %s\n" % (sys.argv[0], "|".join(COMMANDS))) return 2 @@ -240,12 +246,13 @@ def main(): from utils.deprecations import deprecate_old_command_line_tools deprecate_old_command_line_tools() - pid_file = PidFile('dd-agent') + if command in COMMANDS_AGENT: + pid_file = PidFile('dd-agent') - if options.clean: - pid_file.clean() + if options.clean: + pid_file.clean() - agent = Agent(pid_file.get_path(), autorestart) + agent = Agent(pid_file.get_path(), autorestart) if command in START_COMMANDS: log.info('Agent version %s' % get_version()) @@ -266,7 +273,7 @@ def main(): agent.status() elif 'info' == command: - return agent.info(verbose=options.verbose) + return Agent.info(verbose=options.verbose) elif 'foreground' == command: logging.info('Running in foreground') diff --git a/daemon.py b/daemon.py index 05d77d9314..86f41d1a62 100644 --- a/daemon.py +++ b/daemon.py @@ -227,7 +227,7 @@ def run(self): """ raise NotImplementedError - + @classmethod def info(self): """ You should override this method when you subclass Daemon. It will be diff --git a/dogstatsd.py b/dogstatsd.py index 09c52a759c..70a7bed599 100755 --- a/dogstatsd.py +++ b/dogstatsd.py @@ -352,6 +352,7 @@ def run(self): if self.autorestart: sys.exit(AgentSupervisor.RESTART_EXIT_STATUS) + @classmethod def info(self): logging.getLogger().setLevel(logging.ERROR) return DogstatsdStatus.print_latest_status() @@ -424,16 +425,23 @@ def main(config_path=None): from utils.deprecations import deprecate_old_command_line_tools deprecate_old_command_line_tools() + COMMANDS_START_DOGSTATSD = [ + 'start', + 'stop', + 'restart', + 'status' + ] + parser = optparse.OptionParser("%prog [start|stop|restart|status]") parser.add_option('-u', '--use-local-forwarder', action='store_true', dest="use_forwarder", default=False) opts, args = parser.parse_args() - reporter, server, cnf = init(config_path, use_watchdog=True, - use_forwarder=opts.use_forwarder, args=args) - pid_file = PidFile('dogstatsd') - daemon = Dogstatsd(pid_file.get_path(), server, reporter, - cnf.get('autorestart', False)) + if not args or args[0] in COMMANDS_START_DOGSTATSD: + reporter, server, cnf = init(config_path, use_watchdog=True, use_forwarder=opts.use_forwarder, args=args) + pid_file = PidFile('dogstatsd') + daemon = Dogstatsd(pid_file.get_path(), server, reporter, + cnf.get('autorestart', False)) # If no args were passed in, run the server in the foreground. if not args: @@ -453,7 +461,7 @@ def main(config_path=None): elif command == 'status': daemon.status() elif command == 'info': - return daemon.info() + return Dogstatsd.info() else: sys.stderr.write("Unknown command: %s\n\n" % command) parser.print_help()