Skip to content

Commit

Permalink
[osx] split GUI and agent
Browse files Browse the repository at this point in the history
* Move config to `/opt/datadog-agent/etc` + additional checks.d directory
  `/opt/datadog-agent/etc/checks.d`
* Update `datadog-agent` script with new location of the agent
* use global supervisor without `user=dd-agent`
* update run directory location for Mac (same as Linux now)
* `flare` for OS X
  • Loading branch information
degemer committed Jul 14, 2015
1 parent 6d771ea commit 3e6c0b1
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 114 deletions.
14 changes: 9 additions & 5 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
AGENT_VERSION = "5.5.0"
DATADOG_CONF = "datadog.conf"
UNIX_CONFIG_PATH = '/etc/dd-agent'
MAC_CONFIG_PATH = '/opt/datadog-agent/etc'
DEFAULT_CHECK_FREQUENCY = 15 # seconds
LOGGING_MAX_BYTES = 5 * 1024 * 1024

Expand Down Expand Up @@ -160,15 +161,15 @@ def _windows_checksd_path():


def _mac_config_path():
return _config_path(os.path.join(os.getcwd()))
return _config_path(MAC_CONFIG_PATH)


def _mac_confd_path():
return _confd_path(os.path.join(os.getcwd()))
return _confd_path(MAC_CONFIG_PATH)


def _mac_checksd_path():
return _checksd_path(os.path.join(os.getcwd()))
return _unix_checksd_path()


def _unix_config_path():
Expand All @@ -185,6 +186,7 @@ def _unix_checksd_path():
cur_path = os.path.dirname(os.path.realpath(__file__))
return _checksd_path(cur_path)


def _config_path(directory):
path = os.path.join(directory, DATADOG_CONF)
if os.path.exists(path):
Expand Down Expand Up @@ -247,6 +249,7 @@ def get_config_path(cfg_path=None, os_name=None):
sys.stderr.write("Please supply a configuration file at %s or in the directory where the Agent is currently deployed.\n" % bad_path)
sys.exit(3)


def get_default_bind_host():
try:
gethostbyname('localhost')
Expand Down Expand Up @@ -326,6 +329,9 @@ def get_config(parse_args=True, cfg_path=None, options=None):
'utf8_decoding': False
}

if Platform.is_mac():
agentConfig['additional_checksd'] = '/opt/datadog-agent/etc/checks.d'

# Config handling
try:
# Find the right config file
Expand Down Expand Up @@ -689,8 +695,6 @@ def get_ssl_certificate(osname, filename):
if os.path.exists(path):
log.debug("Certificate file found at %s" % str(path))
return path
elif osname == 'mac':
return os.path.join(os.getcwd(), filename)
else:
cur_path = os.path.dirname(os.path.realpath(__file__))
path = os.path.join(cur_path, filename)
Expand Down
2 changes: 1 addition & 1 deletion packaging/osx/com.datadoghq.Agent.plist.example
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<string>com.datadoghq.agent</string>
<key>ProgramArguments</key>
<array>
<string>/Applications/Datadog Agent.app/Contents/MacOS/datadog-agent</string>
<string>/opt/datadog-agent/bin/datadog-agent</string>
<string>restart</string>
</array>
<key>UserName</key>
Expand Down
46 changes: 21 additions & 25 deletions packaging/osx/datadog-agent
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,29 +1,20 @@
#!/usr/bin/env sh
SOURCE="${BASH_SOURCE[0]}"
while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
SOURCE="$(readlink "$SOURCE")"
[[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
done
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"

NAME="datadog-agent"
DESC="Datadog Agent"
AGENTPATH="agent"
FORWARDERPATH="ddagent"
DOGSTATSDPATH="dogstatsd"
AGENTCONF="$DIR/../Resources/datadog.conf"
SUPERVISOR_PIDFILE="$DIR/../Resources/run/datadog-supervisord.pid"
SUPERVISOR_CONF_FILE="../Resources/supervisor.conf"
SUPERVISOR_SOCK="$DIR/../Resources/run/datadog-supervisor.sock"
SUPERVISORCTL_PATH="supervisorctl"
SUPERVISORD_PATH="supervisord"

# To find the executables
PATH="$DIR":$PATH

# to be able to run shipped python
PYTHONHOME="$DIR"/../Resources
AGENTPATH="/opt/datadog-agent/agent/agent.py"
FORWARDERPATH="/opt/datadog-agent/agent/ddagent.py"
DOGSTATSDPATH="/opt/datadog-agent/agent/dogstatsd.py"
AGENTCONF="/opt/datadog-agent/etc/datadog.conf"
SUPERVISOR_PIDFILE="/opt/datadog-agent/run/datadog-supervisord.pid"
SUPERVISOR_CONF_FILE="/opt/datadog-agent/etc/supervisor.conf"
SUPERVISOR_SOCK="/opt/datadog-agent/run/datadog-supervisor.sock"
SUPERVISORCTL_PATH="/opt/datadog-agent/bin/supervisorctl"
SUPERVISORD_PATH="/opt/datadog-agent/bin/supervisord"

# be sure to remove PY2APP parameters
unset PYTHONHOME
unset PYTHONPATH


check_status() {
# If the socket exists, we can use supervisorctl
Expand Down Expand Up @@ -127,15 +118,20 @@ case $1 in
exit $?
;;

flare)
shift
$AGENTPATH flare $@
exit $?
;;

jmx)
shift
$AGENTPATH jmx $@
exit $?
;;

*)
echo "Usage: $0 {start|stop|restart|info|status|configcheck|check|jmx}"
echo "Usage: $0 {start|stop|restart|info|status|configcheck|check|flare|jmx}"
exit 2
;;
esac

55 changes: 0 additions & 55 deletions packaging/osx/supervisor.conf

This file was deleted.

13 changes: 0 additions & 13 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,26 +133,13 @@ def __init__(self, **kw):
extra_args = {
'app': ['gui.py'],
'data_files': [
'checks',
'checks.d',
'datadog-cert.pem',
'dogstream',
'images',
'status.html',
],
'options': {
'py2app': {
'optimize': 0,
'iconfile': 'packaging/Agent.icns',
'packages': ['requests', 'supervisor', 'tornado'],
'extra_scripts': [
'agent.py',
'ddagent.py',
'dogstatsd.py',
'jmxfetch.py',
'supervisorctl.py',
'supervisord.py',
],
'plist': plist
}
}
Expand Down
14 changes: 11 additions & 3 deletions utils/flare.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def __init__(self, cmdline=False, case_id=None):
# Otherwise emit a warning, and ask for confirmation
@staticmethod
def check_user_rights():
if Platform.is_unix() and not os.geteuid() == 0:
if Platform.is_linux() and not os.geteuid() == 0:
log.warning("You are not root, some information won't be collected")
choice = raw_input('Are you sure you want to continue [y/N]? ')
if choice.strip().lower() not in ['yes', 'y']:
Expand Down Expand Up @@ -413,7 +413,11 @@ def _supervisor_status(self):

# Find the agent exec (package or source)
def _get_path_agent_exec(self):
agent_exec = '/etc/init.d/datadog-agent'
if Platform.is_mac():
agent_exec = '/opt/datadog-agent/bin/datadog-agent'
else:
agent_exec = '/etc/init.d/datadog-agent'

if not os.path.isfile(agent_exec):
agent_exec = os.path.join(
os.path.dirname(os.path.realpath(__file__)),
Expand All @@ -433,7 +437,11 @@ def _get_path_supervisor_exec(self):

# Find the supervisor conf (package or source)
def _get_path_supervisor_conf(self):
supervisor_conf = '/etc/dd-agent/supervisor.conf'
if Platform.is_mac():
supervisor_conf = '/opt/datadog-agent/etc/supervisor.conf'
else:
supervisor_conf = '/etc/dd-agent/supervisor.conf'

if not os.path.isfile(supervisor_conf):
supervisor_conf = os.path.join(
os.path.dirname(os.path.realpath(__file__)),
Expand Down
13 changes: 2 additions & 11 deletions utils/pidfile.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
# stdlib
import logging
import os.path
import tempfile

from utils.platform import Platform

log = logging.getLogger(__name__)


Expand All @@ -14,15 +13,7 @@ class PidFile(object):
def get_dir(cls, run_dir=None):
if run_dir is None:
my_dir = os.path.dirname(os.path.abspath(__file__))
if Platform.is_mac():
# py2app compress this file (.pyc) in
# /Applications/Datadog Agent.app/Contents/Resources\
# /lib/python2.7/site-packages.zip/utils/
# which is not a real directory, so we're using this trick
run_dir = '/'.join(my_dir.split('/')[:-4])
else:
run_dir = os.path.join(my_dir, '..', '..')
run_dir = os.path.join(run_dir, 'run')
run_dir = os.path.realpath(os.path.join(my_dir, '..', '..', 'run'))

if os.path.exists(run_dir) and os.access(run_dir, os.W_OK):
return os.path.realpath(run_dir)
Expand Down
2 changes: 1 addition & 1 deletion win32/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -764,7 +764,7 @@ def info_popup(message, parent=None):
add_image_path(osp.join(os.getcwd(), 'images'))
# add datadog-agent in PATH
os.environ['PATH'] = "{0}:{1}".format(
osp.join(os.getcwd(), '../MacOS'),
'/opt/datadog-agent/bin/',
os.environ['PATH']
)
win = SystemTray() if len(sys.argv) < 2 else MainWindow()
Expand Down

0 comments on commit 3e6c0b1

Please sign in to comment.