#!/opt/vdops/bin/perl # This program changes the value of an IPC::Shareable variable to '1' # It works in conjunction with 'ping-swatch' to determine whether or not # swatch is functioning # V Who When What # --------------------------------------------------------------------------- # 1.0.1 skendric 06-21-2007 Fiddle with log messages # 1.0.0 skendric 12-16-2006 First version # Load modules use strict; use warnings; use English; use IPC::Shareable; use Sys::Syslog; # Declare global variables my $alive; # Boolean telling us whether or not swatch is alive my $alive_knot; # IPC::Shareable object my %knot_options; # Options to hand to IPC::Shareable my $glue = 'pisw'; # IPC::Shareable memory segment identifier my $version = '1.0.1'; # Define global variables $alive = 0; %knot_options = ( key => $glue, create => 0, exclusive => 0, mode => 0644, destroy => 0, ); ### Begin Main Program ############################################### { # Leave tracks log_it("Starting $PROGRAM_NAME v$version"); # Tie shared memory segment eval { $alive_knot = tie $alive, 'IPC::Shareable', $glue, { %knot_options } }; if ($@ ne "") { log_it("Unable to tie 'alive' via IPC::Shareable: $@"); die "Unable to tie 'alive' via IPC::Shareable: $@"; } $alive = 1; # Evaluate result if ($alive) { log_it('Yes I am here'); } else { log_it('Unable to set $alive'); } # Leave tracks log_it("Ending $PROGRAM_NAME v$version"); } ######################################################################## # Log message to syslog ######################################################################## sub log_it { my $msg = shift; $Sys::Syslog::host = 'localhost'; $Sys::Syslog::host = $Sys::Syslog::host; # Avoid warning # Send it to syslog openlog($PROGRAM_NAME, 'nofatal,pid', 'local5'); syslog('info', $msg); closelog(); }