diff --git a/manifests/agent.pp b/manifests/agent.pp index 4257f15..450bd27 100644 --- a/manifests/agent.pp +++ b/manifests/agent.pp @@ -253,6 +253,16 @@ class monasca::agent( before => Service['monasca-agent'], } + $log_dir = "${::monasca::log_dir}/agent" + file { "${agent_dir}/supervisor.conf": + ensure => $ensure, + owner => 'root', + group => 'root', + mode => '0644', + content => template('monasca/supervisor.conf.erb'), + notify => Service['monasca-agent'], + } + if $enabled { $ensure = 'running' } else { diff --git a/manifests/virtualenv/agent_instance.pp b/manifests/virtualenv/agent_instance.pp index 10b62bb..68302a3 100644 --- a/manifests/virtualenv/agent_instance.pp +++ b/manifests/virtualenv/agent_instance.pp @@ -44,9 +44,6 @@ define monasca::virtualenv::agent_instance( validate_re($ensure, $valid_values, "Unknown value '${ensure}' for ensure, must be present or absent") - $req_dest = "${basedir}/${venv_prefix}-requirements.txt" - $venv_path = "${basedir}/${venv_prefix}-venv" - monasca::virtualenv::instance { $name: ensure => $ensure, basedir => $basedir, @@ -58,13 +55,4 @@ define monasca::virtualenv::agent_instance( require => [File[$basedir],Package['python-virtualenv'], Package['python-dev']], } - -> - file { "${venv_path}/share/monasca/agent/supervisor.conf": - ensure => $ensure, - owner => 'root', - group => 'root', - mode => '0644', - content => template('monasca/supervisor.conf.erb'), - notify => Service['monasca-agent'], - } } diff --git a/templates/monasca-agent.init.erb b/templates/monasca-agent.init.erb index c62b4cd..9493767 100755 --- a/templates/monasca-agent.init.erb +++ b/templates/monasca-agent.init.erb @@ -11,22 +11,23 @@ ### END INIT INFO . <%= @virtual_env %>/bin/activate -. /lib/lsb/init-functions -PATH=$PATH:/sbin # add the location of start-stop-daemon on Debian -export PYTHONPATH=$PYTHONPATH:/usr/monasca/agent/ -AGENTPATH="<%= @virtual_env %>/bin/monasca-collector" -AGENTCONF="/etc/monasca/agent/agent.yaml" -MONASCASTATSDPATH="<%= @virtual_env %>/bin/monasca-statsd" -AGENTUSER="monasca-agent" -FORWARDERPATH="<%= @virtual_env %>/bin/monasca-forwarder" +PATH=$PATH:/usr/local/bin # supervisord might live here +PATH=$PATH:/sbin + +AGENTPATH="<%= virtual_env %>/bin/monasca-collector" +AGENTCONF="<%= agent_dir %>/agent.yaml" +MONASCASTATSDPATH="<%= virtual_env %>/bin/monasca-statsd" +AGENTUSER="<%= agent_user %>" +FORWARDERPATH="<%= virtual_env %>/bin/monasca-forwarder" NAME="monasca-agent" DESC="Monasca Monitoring Agent" -AGENT_PID_PATH="/var/run/monasca-agent.pid" -SUPERVISOR_PIDFILE="/var/run/monasca-agent-supervisord.pid" -SUPERVISOR_FILE="<%= @virtual_env %>/share/monasca/agent/supervisor.conf" +AGENT_PID_PATH="/var/tmp/monasca-agent.pid" +SUPERVISOR_PIDFILE="/var/tmp/monasca-agent-supervisord.pid" +SUPERVISOR_FILE="<%= agent_dir %>/supervisor.conf" SUPERVISOR_SOCK="/var/tmp/monasca-agent-supervisor.sock" -SUPERVISORD=$(which supervisord) +SUPERVISORD="<%= virtual_env %>/bin/supervisord" +SUPERVISORCTL="<%= virtual_env %>/bin/supervisorctl" # This script is considered a configuration file and will not be # removed by dpkg unless the --purge option it set. Therefore we @@ -44,7 +45,7 @@ check_status() { # same as the number of programs specified in the supervisor config # file: - supervisor_processes=$(supervisorctl -c $SUPERVISOR_FILE status) + supervisor_processes=$($SUPERVISORCTL -c $SUPERVISOR_FILE status) supervisor_processes=$(echo "$supervisor_processes" | grep -v pup | grep $NAME | @@ -82,15 +83,15 @@ case "$1" in su $AGENTUSER -c "$AGENTPATH configcheck" > /dev/null if [ $? -ne 0 ]; then - log_daemon_msg "Invalid check configuration. Please run sudo /etc/init.d/monasca-agent configtest for more details." - log_daemon_msg "Resuming starting process." + echo "Invalid check configuration. Please run sudo /etc/init.d/monasca-agent configtest for more details." + echo "Resuming starting process." fi - log_daemon_msg "Starting $DESC (using supervisord)" "$NAME" - start-stop-daemon --start --quiet --oknodo --exec $SUPERVISORD -- -c $SUPERVISOR_FILE --pidfile $SUPERVISOR_PIDFILE + echo "Starting $DESC (using supervisord)" "$NAME" + $SUPERVISORD -c $SUPERVISOR_FILE -u $AGENTUSER --pidfile $SUPERVISOR_PIDFILE if [ $? -ne 0 ]; then - log_end_msg 1 + exit $? fi # check if the agent is running once per second for 10 seconds @@ -98,7 +99,6 @@ case "$1" in while [ $retries -gt 1 ]; do if check_status > /dev/null; then # We've started up successfully. Exit cleanly - log_end_msg 0 exit 0 else retries=$(($retries - 1)) @@ -106,23 +106,27 @@ case "$1" in fi done # After 10 tries the agent didn't start. Report an error - log_end_msg 1 + exit 1 check_status # report what went wrong $0 stop exit 1 ;; stop) - log_daemon_msg "Stopping $DESC (stopping supervisord)" "$NAME" - start-stop-daemon --stop --retry 30 --quiet --oknodo --pidfile $SUPERVISOR_PIDFILE - - log_end_msg $? + echo "Stopping $DESC (stopping supervisord)" "$NAME" + if [ -e $SUPERVISOR_PIDFILE ]; then + kill `cat $SUPERVISOR_PIDFILE` + else + echo "Pid file $SUPERVISOR_PIDFILE not found, nothing to stop" + fi + + exit $? ;; info) shift # Shift 'info' out of args so we can pass any - # addtional options to the real command + # additional options to the real command # (right now only monasca-agent supports additional flags) su $AGENTUSER -c "$AGENTPATH info $@" COLLECTOR_RETURN=$? @@ -139,6 +143,7 @@ case "$1" in restart|force-reload) $0 stop + sleep 1 $0 start ;; @@ -159,10 +164,9 @@ case "$1" in ;; *) - N=/etc/init.d/$NAME - echo "Usage: $N {start|stop|restart|info|status|configcheck|configtest|jmx}" + echo "Usage: /etc/init.d/$NAME {{start|stop|restart|info|status|configcheck|configtest|jmx}}" exit 1 ;; esac -exit $? \ No newline at end of file +exit $? diff --git a/templates/supervisor.conf.erb b/templates/supervisor.conf.erb index a7fbf5a..bf6d0f5 100644 --- a/templates/supervisor.conf.erb +++ b/templates/supervisor.conf.erb @@ -11,35 +11,38 @@ supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface minfds = 1024 minprocs = 200 loglevel = info -logfile = /var/log/monasca/agent/supervisord.log +logfile = <%= log_dir %>/supervisord.log logfile_maxbytes = 50MB nodaemon = false pidfile = /var/run/monasca-agent-supervisord.pid logfile_backups = 10 [program:collector] -command=<%= @venv_path %>/bin/monasca-collector foreground +command=<%= virtual_env %>/bin/monasca-collector foreground stdout_logfile=NONE stderr_logfile=NONE priority=999 startsecs=2 -user=monasca-agent +user=<%= agent_user %> +autorestart=true [program:forwarder] -command=<%= @venv_path %>/bin/monasca-forwarder +command=<%= virtual_env %>/bin/monasca-forwarder stdout_logfile=NONE stderr_logfile=NONE startsecs=3 priority=998 -user=monasca-agent +user=<%= agent_user %> +autorestart=true -[program:monstatsd] -command=<%= @venv_path %>/bin/monasca-statsd +[program:statsd] +command=<%= virtual_env %>/bin/monasca-statsd stdout_logfile=NONE stderr_logfile=NONE startsecs=3 priority=998 -user=monasca-agent +user=<%= agent_user %> +autorestart=true [group:monasca-agent] -programs=forwarder,collector,monstatsd +programs=forwarder,collector,statsd