From eff434b5961c7dceb941989509de50467fd60410 Mon Sep 17 00:00:00 2001 From: Wedge Date: Wed, 27 Jul 2016 16:44:01 +0300 Subject: [PATCH 1/9] Update script --- init.d/cloudstats-agent | 12 +++++++++--- update_cloudstats.sh | 9 +++++++++ 2 files changed, 18 insertions(+), 3 deletions(-) create mode 100755 update_cloudstats.sh diff --git a/init.d/cloudstats-agent b/init.d/cloudstats-agent index fa4c840..4cc1fde 100755 --- a/init.d/cloudstats-agent +++ b/init.d/cloudstats-agent @@ -23,11 +23,12 @@ progpath='/home/cloudstats_agent/cloudstats-agent' # binary name prog=cloudstats-agent +update_script=update_cloudstats.sh keepalive_prog="$homepath/keepalive" # pid file pidfile="/var/run/${prog}.pid" - +update_pidfile="/var/run/update_cloudstats.pid" # check the binary if not there exit ! [ -x $progpath ] && echo "$progpath: Agent not found" && exit 1 @@ -56,6 +57,10 @@ start() { local pid=$! echo $pid > $pidfile + ENV=production $homepath$update_script > /dev/null 2>&1 & + local update_pid=$1 + echo $update_pid > $update_pidfile + # check again if it's running ps -p $pid >/dev/null 2>&1 eval_cmd $? @@ -63,14 +68,15 @@ start() { stop() { # check if it's running - local pids="$(pidof -cx $keepalive_prog) $(pidof -c $prog)" + local pids="$(pidof -cx $keepalive_prog) $(pidof -c $prog) $(pidof -cx $update_script)" - if [ ${#pids} -lt 2 ]; then + if [ ${#pids} -lt 3 ]; then echo "$prog not running" return 0 fi printf "%-50s%s" "Stopping $prog: " '' rm -f $pidfile + rm -f $update_pidfile kill -9 $pids eval_cmd $? } diff --git a/update_cloudstats.sh b/update_cloudstats.sh new file mode 100755 index 0000000..0edba93 --- /dev/null +++ b/update_cloudstats.sh @@ -0,0 +1,9 @@ +#!/bin/sh + +export INSTALL_PATH="/home/cloudstats_agent" + +while : +do + bundle exec ruby lib/cloudstats.rb --update + sleep 5h +done From 95851dc30cae6488bf195da51765efe386588c58 Mon Sep 17 00:00:00 2001 From: Wedge Date: Wed, 27 Jul 2016 16:50:25 +0300 Subject: [PATCH 2/9] Comment out old update code --- lib/cloudstats/scheduler.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/cloudstats/scheduler.rb b/lib/cloudstats/scheduler.rb index b9737bd..74ee3f6 100644 --- a/lib/cloudstats/scheduler.rb +++ b/lib/cloudstats/scheduler.rb @@ -39,12 +39,12 @@ def schedule publisher.publish end - $logger.info "Scheduling updates every #{update_rate}" - scheduler.every update_rate do - $logger.catch_and_log_socket_error(Updater.STORAGE_SERVICE) do - Updater.new.update - end - end +# $logger.info "Scheduling updates every #{update_rate}" +# scheduler.every update_rate do +# $logger.catch_and_log_socket_error(Updater.STORAGE_SERVICE) do +# Updater.new.update +# end +# end $logger.info "Scheduling backups" scheduler.cron '0 0 * * *' do From 22c7e1d460a2222a09faee883d79b05609ceaa0d Mon Sep 17 00:00:00 2001 From: Andrei Gliga Date: Wed, 27 Jul 2016 17:30:31 +0300 Subject: [PATCH 3/9] update every 5 minutes --- update_cloudstats.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/update_cloudstats.sh b/update_cloudstats.sh index 0edba93..641521e 100755 --- a/update_cloudstats.sh +++ b/update_cloudstats.sh @@ -5,5 +5,5 @@ export INSTALL_PATH="/home/cloudstats_agent" while : do bundle exec ruby lib/cloudstats.rb --update - sleep 5h + sleep 5m done From bc2ed417fa643d1c2d129823e6a78e6cf2b2bb7a Mon Sep 17 00:00:00 2001 From: Andrei Gliga Date: Wed, 27 Jul 2016 17:45:38 +0300 Subject: [PATCH 4/9] renamed: update_cloudstats.sh -> packaging/cagent_updater.sh --- update_cloudstats.sh => packaging/cagent_updater.sh | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename update_cloudstats.sh => packaging/cagent_updater.sh (100%) diff --git a/update_cloudstats.sh b/packaging/cagent_updater.sh similarity index 100% rename from update_cloudstats.sh rename to packaging/cagent_updater.sh From c8e1685acec3cb851ce279d7ce0d09f41c134310 Mon Sep 17 00:00:00 2001 From: Andrei Gliga Date: Wed, 27 Jul 2016 17:45:55 +0300 Subject: [PATCH 5/9] use the cagent_updater --- init.d/cloudstats-agent | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/init.d/cloudstats-agent b/init.d/cloudstats-agent index 4cc1fde..6fa36c4 100755 --- a/init.d/cloudstats-agent +++ b/init.d/cloudstats-agent @@ -23,12 +23,12 @@ progpath='/home/cloudstats_agent/cloudstats-agent' # binary name prog=cloudstats-agent -update_script=update_cloudstats.sh +update_script=cagent_updater keepalive_prog="$homepath/keepalive" # pid file pidfile="/var/run/${prog}.pid" -update_pidfile="/var/run/update_cloudstats.pid" +update_pidfile="/var/run/cagent_updater.pid" # check the binary if not there exit ! [ -x $progpath ] && echo "$progpath: Agent not found" && exit 1 From 6cce7b5a9db3fceead619eaf75e7063115ae0ba1 Mon Sep 17 00:00:00 2001 From: Andrei Gliga Date: Wed, 27 Jul 2016 17:46:05 +0300 Subject: [PATCH 6/9] package the cagent_updater --- Rakefile | 1 + 1 file changed, 1 insertion(+) diff --git a/Rakefile b/Rakefile index af2bb4b..2d04e45 100644 --- a/Rakefile +++ b/Rakefile @@ -238,6 +238,7 @@ def create_package(target) sh "cp packaging/wrapper.sh #{package_dir}/#{PROFILE[:package_name]}" sh "cp packaging/keepalive #{package_dir}/keepalive" sh "cp packaging/reset-key.sh #{package_dir}/reset-key" + sh "cp packaging/cagent_updater.sh #{package_dir}/cagent_updater" sh "chmod +x #{package_dir}/#{PROFILE[:package_name]}" sh "cp -pR packaging/vendor #{package_dir}/lib/" sh "cp Gemfile Gemfile.lock #{package_dir}/lib/vendor/" From 1cb412f5f751bc45404f3755ca97162ca1ae9a06 Mon Sep 17 00:00:00 2001 From: Andrei Gliga Date: Wed, 27 Jul 2016 18:06:47 +0300 Subject: [PATCH 7/9] the right executable --- packaging/cagent_updater.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/cagent_updater.sh b/packaging/cagent_updater.sh index 641521e..50de359 100755 --- a/packaging/cagent_updater.sh +++ b/packaging/cagent_updater.sh @@ -4,6 +4,6 @@ export INSTALL_PATH="/home/cloudstats_agent" while : do - bundle exec ruby lib/cloudstats.rb --update + /home/cloudstats_agent/cloudstats-agent --update sleep 5m done From 37c541af53015a68bb9e546328202bedbbb10724 Mon Sep 17 00:00:00 2001 From: Andrei Gliga Date: Wed, 27 Jul 2016 18:16:14 +0300 Subject: [PATCH 8/9] missing / between the homepath and the update script --- init.d/cloudstats-agent | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/init.d/cloudstats-agent b/init.d/cloudstats-agent index 6fa36c4..97257d6 100755 --- a/init.d/cloudstats-agent +++ b/init.d/cloudstats-agent @@ -57,7 +57,7 @@ start() { local pid=$! echo $pid > $pidfile - ENV=production $homepath$update_script > /dev/null 2>&1 & + ENV=production $homepath/$update_script > /dev/null 2>&1 & local update_pid=$1 echo $update_pid > $update_pidfile From c50cf61e2a059bb4fa6bd5600a74905dcd918c66 Mon Sep 17 00:00:00 2001 From: Andrei Gliga Date: Wed, 27 Jul 2016 18:16:28 +0300 Subject: [PATCH 9/9] no need to set the env to production --- init.d/cloudstats-agent | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/init.d/cloudstats-agent b/init.d/cloudstats-agent index 97257d6..e52cf01 100755 --- a/init.d/cloudstats-agent +++ b/init.d/cloudstats-agent @@ -57,7 +57,7 @@ start() { local pid=$! echo $pid > $pidfile - ENV=production $homepath/$update_script > /dev/null 2>&1 & + $homepath/$update_script > /dev/null 2>&1 & local update_pid=$1 echo $update_pid > $update_pidfile