diff --git a/pandora_agents/unix/ChangeLog b/pandora_agents/unix/ChangeLog index 0882cfa7bb..cec6f10bb9 100644 --- a/pandora_agents/unix/ChangeLog +++ b/pandora_agents/unix/ChangeLog @@ -1,3 +1,11 @@ +2010-11-14 Sancho Lerena + + * plugins/pandora_update: Small tool (in perl), used also in windows + (compiled as .exe), to auto-upgrade the software agents by stopping + replacing the binary, and starting again the service/process, and also + notifying the system about the upgrade. This will be possible using + the new filecollection mechanism in 3.2 version. + 2010-11-10 Miguel de Dios * DEBIAN/postinst, DEBIAN/prerm, DEBIAN/make_deb_package.sh: fixed the use diff --git a/pandora_agents/unix/plugins/pandora_update b/pandora_agents/unix/plugins/pandora_update new file mode 100755 index 0000000000..8471758638 --- /dev/null +++ b/pandora_agents/unix/plugins/pandora_update @@ -0,0 +1,152 @@ +#!/usr/bin/perl +# Update binary tool +# Copyright (c) 2010 Artica Soluciones Tecnologicas S.L. +# Copyright (c) Sancho Lerena + +use strict; +use warnings; +use POSIX qw(strftime); +use Cwd 'abs_path'; +use File::Basename; +use File::Copy; +use FindBin; +use Digest::MD5 qw(md5); + +# This tool is intented to be used to update pandora agent binaries using +# the file collection feature. This will work using a module like this: + +# Unix + +# module_begin +# module_name Pandora_Update +# module_type async_string +# module_exec nohup pandora_update fc_1 2> /dev/null && tail -1 nohup.out 2> /dev/null +# module_description Module to check new version of pandora agent and update itself +# module_end + +# Windows: + +# module_begin +# module_name Pandora_Update +# module_type async_string +# module_exec pandora_update.exe fc_1 +# module_description Module to check new version of pandora agent and update itself +# module_end + + +# This small function return the current base path (where this tool is stored) + +sub return_basepath () { + return $FindBin::Bin; +} + +# Function to compare two binary files. Return 0 if different 1 if equal, 2 error + +sub compare_twofiles ($$) { + + my $file1 = $_[0]; + my $file2 = $_[1]; + + my $size1 = -s $file1; + my $size2 = -s $file2; + + # Size matters; + + if ((!defined($size1)) || (!defined($size2))){ + return 2; + } + + if ($size1 != $size2){ + return 0; + } + + open FILE1, $file1; + binmode FILE1; + my $data1 = ; + close FILE1; + my $hash1 = md5($data1); + + open FILE2, $file2; + binmode FILE2; + my $data2 = ; + close FILE2; + my $hash2 = md5($data2); + + if ($hash1 eq $hash2){ + return 1; + } + + return 0; +} + +# ------------------------------------------------------------------------- + +# MAIN CODE starts here + + +# 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`; + copy($updated_binary, $running_binary) or die "Problems updating binary from $updated_binary"; + $output = `$start_pandora`; + +} else { + if (-e $local_log){ + print "Updated binary from $updated_binary\n"; + unlink $local_log; + } +} + +exit;