initial commit of file from CVS for e-smith-lib on Wed 12 Jul 08:58:46 BST 2023

This commit is contained in:
Brian Read
2023-07-12 08:58:46 +01:00
parent 6d7e97ea37
commit a527984040
98 changed files with 14369 additions and 2 deletions

View File

@@ -0,0 +1,146 @@
#!/usr/bin/perl -w
#----------------------------------------------------------------------
# copyright (C) 2005 Mitel Networks Corporation
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
#----------------------------------------------------------------------
package esmith;
use strict;
use Errno;
use DirHandle;
my $event = shift || die "must give event name parameter";
chdir "/etc/e-smith/events/$event" or die "Couldn't chdir to event directory /etc/e-smith/events/$event: $!";
my $dh = DirHandle->new("services2adjust");
exit(0) unless $dh; # Nothing to do
use esmith::ConfigDB;
use esmith::util;
my %param2char = (
down => 'd',
stop => 'd',
up => 'u',
start => 'u',
restart => 't',
sigterm => 't',
adjust => 'h',
reload => 'h',
sighup => 'h',
sigusr1 => '1',
sigusr2 => '2',
once => 'o',
pause => 'p',
alarm => 'a',
interrupt => 'i',
quit => 'q',
kill => 'k',
exit => 'x',
);
sub adjust_supervised_service
{
my ($s, @actions) = @_;
my $m = "control fifo for service $s: ";
unless (open(C, ">/service/$s/supervise/control"))
{
warn "Couldn't open $m$!";
return;
}
foreach my $p (@actions)
{
my $c = $param2char{$p};
unless ($c)
{
warn "Unrecognised param $p for service $s\n";
next;
}
warn "adjusting supervised $s ($p)\n";
unless (print C $c)
{
warn "Couldn't write to $m$!";
return;
}
}
warn "Couldn't close $m$!" unless close(C);
}
my $conf = esmith::ConfigDB->open_ro || die "Couldn't open config db";
foreach my $service (grep { !/^\./ } $dh->read())
{
my $s = $conf->get($service);
unless ($s)
{
warn "No conf db entry for service $service\n";
next;
}
my $f = "services2adjust/$service";
my @actions;
if (-l "$f")
{
@actions = ( readlink "$f" );
}
else
{
if (open(F, $f))
{
# Read list of actions from the file, and untaint
@actions = map { chomp; /([a-z]+[12]?)/ ; $1 } <F>;
close(F);
}
else
{
warn "Could not open $f: $!";
}
}
# if service is supervised and not handled by systemd
if (-d "/service/$service" && glob("/etc/rc7.d/S??$service"))
{
my $enabled = ($s->prop('status') || 'disabled') eq 'enabled';
adjust_supervised_service($service,
# stop the service if it is now disabled
$enabled ? () : 'down',
# Send the specified signal(s) to the running daemon
@actions,
# bring the service up if it is enabled (and we're not
# stopping it or running it once)
($enabled && !grep { /^(down|stop|d|once|o)$/ } @actions) ? 'up' : (),
);
}
# for service handled by former sysvinit or directly with systemd
else
{
my $enabled = ($s->prop('status') || 'disabled') eq 'enabled';
# bring the service up if it is enabled (and we're not stopping it or running it once, or using signal able to start it)
unshift(@actions,'start') if ($enabled && !grep { /^(down|stop|d|once|o|start|restart|reload-or-restart)$/ } @actions) ;
# stop the service if it is disabled
@actions = ('stop') unless $enabled;
foreach (@actions)
{
warn "adjusting non-supervised $service ($_)\n";
esmith::util::serviceControl(
NAME => $service,
ACTION => $_,
);
}
}
}

View File

@@ -0,0 +1,61 @@
#! /usr/bin/perl -w
#----------------------------------------------------------------------
# copyright (C) 2003-2007 Mitel Networks Corporation
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
#----------------------------------------------------------------------
use strict;
use File::Find;
use File::Copy;
use esmith::templates;
sub expand;
my $event = shift or die "Event name is required\n";
my $filename;
my %args;
my ($param, $value);
my $templates_dir = "/etc/e-smith/events/$event/templates2expand";
exit 0 unless -d $templates_dir;
chdir $templates_dir or die "Could not chdir to $templates_dir: $!\n";;
# Walk the tree and expand all templates referenced thereunder.
find({
no_chdir => 1,
follow => 0,
wanted => \&expand,
},
'.'
);
exit 0;
sub expand
{
return unless -f $_;
# For each file found, read the file to find
# processTemplate args, then expand the template
s/^\.//;
$filename = $_;
warn "expanding $filename\n";
esmith::templates::processTemplate({
MORE_DATA => { EVENT => $event },
TEMPLATE_PATH => $filename,
OUTPUT_FILENAME => $filename,
});
}

View File

@@ -0,0 +1,35 @@
#!/usr/bin/perl -w
#----------------------------------------------------------------------
# copyright (C) 1999-2003 Mitel Networks Corporation
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# Technical support for this program is available from Mitel Networks
# Please visit our web site www.mitel.com/sme/ for details.
#----------------------------------------------------------------------
package esmith;
use strict;
use esmith::util;
if (esmith::util::initialize_default_databases())
{
exit 0;
}
else
{
exit 1;
}

View File