diff --git a/agent.py b/agent.py index 477971e8a9..f6f1b3df24 100755 --- a/agent.py +++ b/agent.py @@ -54,8 +54,6 @@ PID_DIR = None WATCHDOG_MULTIPLIER = 10 RESTART_INTERVAL = 4 * 24 * 60 * 60 # Defaults to 4 days -START_COMMANDS = ['start', 'restart', 'foreground'] -DD_AGENT_COMMANDS = ['check', 'flare', 'jmx'] DEFAULT_COLLECTOR_PROFILE_INTERVAL = 20 @@ -362,6 +360,7 @@ def main(): autorestart = agentConfig.get('autorestart', False) hostname = get_hostname(agentConfig) in_developer_mode = agentConfig.get('developer_mode') + COMMANDS_AGENT = [ 'start', 'stop', @@ -389,18 +388,14 @@ def main(): sys.stderr.write("Unknown command: %s\n" % command) return 3 - # Deprecation notice - if command not in DD_AGENT_COMMANDS: - # Will become an error message and exit after deprecation period - from utils.deprecations import deprecate_old_command_line_tools - deprecate_old_command_line_tools() + # TODO: actually kill the start/stop/restart/status command for 5.11 + if command in ['start', 'stop', 'restart', 'status'] and not in_developer_mode: + logging.error('Please use supervisor to manage the agent') + return 1 if command in COMMANDS_AGENT: agent = Agent(PidFile(PID_NAME, PID_DIR).get_path(), autorestart, in_developer_mode=in_developer_mode) - if command in START_COMMANDS: - log.info('Agent version %s' % get_version()) - if 'start' == command: log.info('Start daemon') agent.start() @@ -420,6 +415,7 @@ def main(): return Agent.info(verbose=options.verbose) elif 'foreground' == command: + log.info('Agent version %s' % get_version()) if autorestart: # Set-up the supervisor callbacks and fork it. logging.info('Running Agent with auto-restart ON') diff --git a/ddagent.py b/ddagent.py index bd215b7760..2a24fe17bc 100755 --- a/ddagent.py +++ b/ddagent.py @@ -579,10 +579,6 @@ def sigterm_handler(signum, frame): def main(): - # Deprecation notice - from utils.deprecations import deprecate_old_command_line_tools - deprecate_old_command_line_tools() - define("sslcheck", default=1, help="Verify SSL hostname, on by default") define("use_simple_http_client", default=0, help="Use Tornado SimpleHTTPClient instead of CurlAsyncHTTPClient") args = parse_command_line() diff --git a/dogstatsd.py b/dogstatsd.py index bc00647e31..0c62271c82 100755 --- a/dogstatsd.py +++ b/dogstatsd.py @@ -544,10 +544,6 @@ def init(config_path=None, use_watchdog=False, use_forwarder=False, args=None): def main(config_path=None): """ The main entry point for the unix version of dogstatsd. """ - # Deprecation notice - from utils.deprecations import deprecate_old_command_line_tools - deprecate_old_command_line_tools() - COMMANDS_START_DOGSTATSD = [ 'start', 'stop', @@ -560,10 +556,12 @@ def main(config_path=None): dest="use_forwarder", default=False) opts, args = parser.parse_args() + in_developer_mode = 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) daemon = Dogstatsd(PidFile(PID_NAME, PID_DIR).get_path(), server, reporter, cnf.get('autorestart', False)) + in_developer_mode = cnf.get('developer_mode') # If no args were passed in, run the server in the foreground. if not args: @@ -574,6 +572,11 @@ def main(config_path=None): else: command = args[0] + # TODO: actually kill the start/stop/restart/status command for 5.11 + if command in ['start', 'stop', 'restart', 'status'] and not in_developer_mode: + logging.error('Please use supervisor to manage the agent') + return 1 + if command == 'start': daemon.start() elif command == 'stop': diff --git a/tests/core/test_autorestart.py b/tests/core/test_autorestart.py deleted file mode 100644 index 94250cd26e..0000000000 --- a/tests/core/test_autorestart.py +++ /dev/null @@ -1,99 +0,0 @@ -# stdlib -import os -import shlex -import signal -import subprocess -import time -import unittest - -# 3p -from nose.plugins.attrib import attr - - -@attr('unix') -@attr(requires='core_integration') -class TestAutoRestart(unittest.TestCase): - """ Test the auto-restart and forking of the agent """ - def setUp(self): - self.agent_foreground = None - self.agent_daemon = None - - def tearDown(self): - if self.agent_foreground: - self.agent_foreground.kill() - if self.agent_daemon: - args = shlex.split('python agent.py stop') - subprocess.Popen(args).communicate() - - def _start_foreground(self): - # Run the agent in the foreground with auto-restarting on. - args = shlex.split('python agent.py foreground --autorestart') - self.agent_foreground = subprocess.Popen(args) - time.sleep(5) - - def _start_daemon(self): - args = shlex.split('python agent.py start --autorestart') - self.agent_daemon = subprocess.Popen(args) - time.sleep(5) - - def _get_child_parent_pids(self, grep_str): - args = shlex.split('pgrep -f "%s"' % grep_str) - pgrep = subprocess.Popen(args, stdout=subprocess.PIPE, - close_fds=True).communicate()[0] - pids = pgrep.strip().split('\n') - assert len(pids) == 2, pgrep - - return sorted([int(p) for p in pids], reverse=True) - - def test_foreground(self): - self._start_foreground() - - grep_str = 'agent.py foreground' - child_pid, parent_pid = self._get_child_parent_pids(grep_str) - - # Try killing the parent proc, confirm that the child is killed as well. - os.kill(parent_pid, signal.SIGTERM) - os.waitpid(parent_pid, 0) - time.sleep(6) - self.assertRaises(OSError, os.kill, child_pid, signal.SIGTERM) - - # Restart the foreground agent. - self._start_foreground() - child_pid, parent_pid = self._get_child_parent_pids(grep_str) - - # Set a SIGUSR1 to the child to force an auto-restart exit. - os.kill(child_pid, signal.SIGUSR1) - time.sleep(6) - - # Confirm that the child is still alive - child_pid, parent_pid = self._get_child_parent_pids(grep_str) - - # Kill the foreground process. - self.agent_foreground.terminate() - self.agent_foreground = None - - def test_daemon(self): - self._start_daemon() - - grep_str = 'agent.py start' - child_pid, parent_pid = self._get_child_parent_pids(grep_str) - - # Try killing the parent proc, confirm that the child is killed as well. - os.kill(parent_pid, signal.SIGTERM) - time.sleep(6) - self.assertRaises(OSError, os.kill, child_pid, signal.SIGTERM) - - # Restart the daemon agent. - self._start_daemon() - child_pid, parent_pid = self._get_child_parent_pids(grep_str) - - # Set a SIGUSR1 to the child to force an auto-restart exit. - os.kill(child_pid, signal.SIGUSR1) - time.sleep(6) - - # Confirm that the child is still alive - child_pid, parent_pid = self._get_child_parent_pids(grep_str) - - # Kill the daemon process. - os.kill(parent_pid, signal.SIGTERM) - self.agent_daemon = None diff --git a/utils/deprecations.py b/utils/deprecations.py deleted file mode 100644 index 7a14f5f64f..0000000000 --- a/utils/deprecations.py +++ /dev/null @@ -1,17 +0,0 @@ -# (C) Datadog, Inc. 2010-2016 -# All rights reserved -# Licensed under Simplified BSD License (see LICENSE) - -import logging -from os.path import basename -import sys - -log = logging.getLogger(__name__) - - -def deprecate_old_command_line_tools(): - name = basename(sys.argv[0]) - if name in ['dd-forwarder', 'dogstatsd', 'dd-agent']: - log.warn("Using this command is deprecated and will be removed in a future version," - " for more information see " - "https://github.com/DataDog/dd-agent/wiki/Deprecation-notice--(old-command-line-tools)")