diff --git a/pandora_agents/unix/ChangeLog b/pandora_agents/unix/ChangeLog index b646b39a02..99aea0c3ab 100644 --- a/pandora_agents/unix/ChangeLog +++ b/pandora_agents/unix/ChangeLog @@ -1,3 +1,7 @@ +2011-04-04 Dario Rodriguez + + * plugins/pandora_update: Modified plugin for agent autoupdate. + 2011-03-09 Ramon Novoa * pandora_agent: Fixed a typo. diff --git a/pandora_agents/unix/plugins/pandora_update b/pandora_agents/unix/plugins/pandora_update index caa86960e2..8779e0329f 100755 --- a/pandora_agents/unix/plugins/pandora_update +++ b/pandora_agents/unix/plugins/pandora_update @@ -82,6 +82,40 @@ sub compare_twofiles ($$) { return 0; } +# Get agent pid +sub get_agent_pid ($$) { + my $daemon = shift; + my $app_path = shift; + + $ENV{'COLUMNS'}=400; + my $os_name=`uname -s`; + my $pid = ""; + my $cmd = ""; + + if ($os_name eq "HP-UX") { + + $cmd ="ps -ex | grep \"$daemon $app_path\" | grep -v grep | head -1 | awk '{ print \$1 }'"; + } + elsif ($os_name eq "SunOS") { + my $cmd_aux="echo \"$daemon $app_path\" | cut -c1-40"; + my $truncated_daemon = `$cmd_aux`; + + my $zone = `/bin/zonename`; + + if ( $zone eq "global") { + $cmd ="ps -f -z global | grep \"$truncated_daemon\" | grep -v grep | head -1 | awk '{ print \$2 }'"; + } else { + $cmd ="ps -Af | grep \"$truncated_daemon\" | grep -v grep | head -1 | awk '{ print \$2 }'"; + } + } else { + $cmd ="ps -Af | grep \"$daemon $app_path\" | grep -v grep | head -1 | awk '{ print \$2 }'"; + } + + $pid = `$cmd`; + return $pid; + +} + # ------------------------------------------------------------------------- # MAIN CODE starts here @@ -89,14 +123,19 @@ sub compare_twofiles ($$) { # Get the required path (relative to basepath) to find pandora agent binary -if ($#ARGV != 0) { - print "Usage: $0 $local_log"); close (FILE3); - my $output = `$stop_pandora`; + my $ppid = get_agent_pid($running_binary, $conf_path); + + # Kill parent process (a.k.a the Agent) + my $output = `kill -9 $ppid`; sleep SERVICE_STOP_WAIT; + + # Copy the updated agent copy($updated_binary, $running_binary) or unlink $local_log; - $output = `$start_pandora`; + + # Starting the agent again + my $log = $opt_dir."/var/log/pandora/pandora_agent.log"; + $output = `nohup $running_binary $conf_path >/dev/null 2>$log &` + } else { if (-e $local_log){