Improved daemon launcher and installer for FreeBSD.

This commit is contained in:
Junichi Satoh 2021-07-19 13:47:24 +09:00
parent 9183110028
commit b1ce3acd2f
4 changed files with 85 additions and 58 deletions

View File

@ -1,8 +1,8 @@
#!/bin/sh #!/bin/sh
# ********************************************************************** # **********************************************************************
# Pandora FMS Server Daemon launcher for FreeBSD # Pandora FMS Server Daemon launcher through pandora_ha for FreeBSD
# (c) 2010 Junichi Satoh <junichi@rworks.jp> # (c) 2010-2021 Junichi Satoh <junichi@rworks.jp>
# (c) 2014 Koichiro Kikuchi <koichiro@rworks.jp> # (c) 2014 Koichiro Kikuchi <koichiro@rworks.jp>
# #
# ********************************************************************** # **********************************************************************
@ -13,63 +13,51 @@
# Add the following lines to /etc/rc.conf to enable pandora_server: # Add the following lines to /etc/rc.conf to enable pandora_server:
# pandora_server_enable (bool): Set to "YES" to enable pandora_server (default: NO) # pandora_server_enable (bool): Set to "YES" to enable pandora_server (default: NO)
# pandora_server_profiles (str): Define your profiles here (default: "")
# #
. "/etc/rc.subr" . "/etc/rc.subr"
PATH=/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin name="pandora_ha"
name="pandora_server"
rcvar=pandora_server_enable rcvar=pandora_server_enable
: ${pandora_server_enable:=NO} : ${pandora_server_enable:=NO}
: ${pandora_server_configfile:=/usr/local/etc/pandora/pandora_server.conf} : ${pandora_server_configfile:=/usr/local/etc/pandora/pandora_server.conf}
command=/usr/local/bin/${name} command=/usr/local/bin/pandora_ha
command_args="-D" command_pandora=/usr/local/bin/pandora_server
command_interpreter=/usr/local/bin/perl command_interpreter=/usr/local/bin/perl
_pidprefix=/var/run/$name _pidprefix=/var/run/pandora_ha
_pidprefix_pandora=/var/run/pandora_server
pidfile=${_pidprefix}.pid pidfile=${_pidprefix}.pid
pidfile_pandora=${_pidprefix_pandora}.pid
required_files="$pandora_server_configfile" required_files="$pandora_server_configfile"
extra_commands="status_server start_server stop_server restart_server"
stop_postcmd=stop_postcmd
status_server_cmd=control_pandora_server
start_server_cmd=control_pandora_server
stop_server_cmd=control_pandora_server
restart_server_cmd=control_pandora_server
load_rc_config $name load_rc_config $name
if [ "$2" ]; then control_pandora_server() {
profile="$2" local name command pidfile
if [ "$pandora_server_profiles" ]; then name="pandora_server"
pidfile="${_pidprefix}.${profile}.pid" command=$command_pandora
eval pandora_server_configfile="\${pandora_server_${profile}_configfile:-}" pidfile=$pidfile_pandora
if [ -z "$pandora_server_configfile" ]; then pandora_server_flags="-D $pandora_server_flags -P $pidfile_pandora $pandora_server_configfile"
echo "You must define a configuration file (pandora_server_${profile}_configfile)" pandora_arg=`echo $rc_arg | sed 's/_server//g'`
exit 1 unset "${pandora_arg}_cmd" "${pandora_arg}_precmd" "${pandora_arg}_postcmd"
fi run_rc_command $pandora_arg
required_files="$pandora_server_configfile" }
eval pandora_server_enable="\${pandora_server_${profile}_enable:-$pandora_server_enable}"
eval pandora_server_flags="\${pandora_server_${profile}_flags:-$pandora_server_flags}"
eval pidfile="\${pandora_server_${profile}_pidfile:-$pidfile}"
else
echo "$0: extra argument ignored"
fi
elif [ "${pandora_server_profiles}" ] && [ "$1" ]; then
for profile in ${pandora_server_profiles}; do
eval _enable="\${pandora_server_${profile}_enable}"
case "${_enable:-${pandora_server_enable}}" in
[Yy][Ee][Ss]);;
*) continue;;
esac
echo "===> pandora_server profile: ${profile}"
/usr/local/etc/rc.d/pandora_server $1 ${profile}
retcode="$?"
if [ "0${retcode}" -ne 0 ]; then
failed="${profile} (${retcode}) ${failed:-}"
else
success="${profile} ${success:-}"
fi
done
exit 0
fi
pandora_server_flags="$pandora_server_flags -P $pidfile $pandora_server_configfile" stop_postcmd()
{
rm -f $pidfile
}
pandora_ha_flags="-d -p $pidfile $pandora_server_configfile"
run_rc_command "$1" run_rc_command "$1"

View File

@ -2,7 +2,7 @@
# ********************************************************************** # **********************************************************************
# Tentacle Server Daemon launcher for FreeBSD # Tentacle Server Daemon launcher for FreeBSD
# (c) 2010-2012 Junichi Satoh <junichi@rworks.jp> # (c) 2010-2021 Junichi Satoh <junichi@rworks.jp>
# #
# ********************************************************************** # **********************************************************************
@ -21,17 +21,23 @@ name="tentacle_server"
rcvar=tentacle_server_enable rcvar=tentacle_server_enable
# read configuration and set defaults # read configuration and set defaults
tentacle_server_enable=${tentacle_server_enable:-"NO"}
tentacle_server_flags=${tentacle_server_flags:-'-a 0.0.0.0 -p 41121 -s /var/spool/pandora/data_in -i.*\.conf:conf\;.*\.md5:md5\;.*\.zip:collections -d'}
tentacle_server_user=${tentacle_server_user:-"pandora"}
load_rc_config $name load_rc_config $name
: ${tentacle_server_enable="NO"}
PATH=/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin : ${tentacle_server_config="/usr/local/etc/tentacle/${name}.conf"}
: ${tentacle_server_pidfile="/var/run/${name}.pid"}
command=/usr/local/bin/${name} command=/usr/local/bin/${name}
command_interpreter=/usr/local/bin/perl command_interpreter=/usr/local/bin/perl
tentacle_server_user=${tentacle_server_user:-"pandora"}
#
# Use tentacle_server.conf by default.
tentacle_server_flags="-F ${tentacle_server_config}"
#
# Each parameters can also be specified as arguments like this:
#tentacle_server_flags=${tentacle_server_flags:-'-a 0.0.0.0 -p 41121 -s /var/spool/pandora/data_in -i.*\.conf:conf\;.*\.md5:md5\;.*\.zip:collections -d'}
#
procname=$command procname=$command
pidfile=/var/run/$name.pid pidfile=${tentacle_server_pidfile}
start_postcmd=start_postcmd start_postcmd=start_postcmd
stop_postcmd=stop_postcmd stop_postcmd=stop_postcmd

View File

@ -407,6 +407,11 @@ install () {
mv ${sh_script}.new $sh_script mv ${sh_script}.new $sh_script
chmod a+x $sh_script chmod a+x $sh_script
done done
# install pandora_ha
INSTALL_DIR="$DESTDIR$PREFIX/bin/"
echo ">Installing the pandora_ha binary to $INSTALL_DIR..."
cp -f $DESTDIR$PANDORA_HOME/util/pandora_ha.pl "$INSTALL_DIR/pandora_ha"
chmod +x "$INSTALL_DIR/pandora_ha"
;; ;;
*) *)
SYSTEMD_DIR=$DESTDIR/etc/systemd/system SYSTEMD_DIR=$DESTDIR/etc/systemd/system

View File

@ -159,6 +159,8 @@ sub help_screen {
############################################################################## ##############################################################################
sub ha_keep_pandora_running($$) { sub ha_keep_pandora_running($$) {
my ($conf, $dbh) = @_; my ($conf, $dbh) = @_;
my $OSNAME = $^O;
my $control_command;
$conf->{'pandora_service_cmd'} = 'service pandora_server' unless defined($conf->{'pandora_service_cmd'}); $conf->{'pandora_service_cmd'} = 'service pandora_server' unless defined($conf->{'pandora_service_cmd'});
@ -179,18 +181,30 @@ sub ha_keep_pandora_running($$) {
$Pandora_Service = $conf->{'pandora_service_cmd'}; $Pandora_Service = $conf->{'pandora_service_cmd'};
# Check if service is running # Check if service is running
my $pid = `$Pandora_Service status-server | awk '{print \$NF*1}' | tr -d '\.'`; $control_command = "stauts-server";
if ($OSNAME eq "freebsd") {
$control_command = "status_server";
}
my $pid = `$Pandora_Service $control_command | awk '{print \$NF*1}' | tr -d '\.'`;
if ( ($pid > 0) && ($component_last_contact > 0)) { if ( ($pid > 0) && ($component_last_contact > 0)) {
# service running but not all components # service running but not all components
log_message($conf, 'LOG', 'Pandora service running but not all components.'); log_message($conf, 'LOG', 'Pandora service running but not all components.');
print ">> service running but delayed...\n"; print ">> service running but delayed...\n";
`$Pandora_Service restart-server 2>/dev/null`; $control_command = "restart-server";
if ($OSNAME eq "freebsd") {
$control_command = "restart_server";
}
`$Pandora_Service $control_command 2>/dev/null`;
} elsif ($pid == 0) { } elsif ($pid == 0) {
# service not running # service not running
log_message($conf, 'LOG', 'Pandora service not running.'); log_message($conf, 'LOG', 'Pandora service not running.');
print ">> service not running...\n"; print ">> service not running...\n";
`$Pandora_Service start-server 2>/dev/null`; $control_command = "start-server";
if ($OSNAME eq "freebsd") {
$control_command = "start_server";
}
`$Pandora_Service $control_command 2>/dev/null`;
} elsif ($pid > 0 } elsif ($pid > 0
&& $nservers == 0 && $nservers == 0
) { ) {
@ -202,7 +216,11 @@ sub ha_keep_pandora_running($$) {
log_message($conf, 'LOG', 'Pandora service running without servers ['.$nservers.'].'); log_message($conf, 'LOG', 'Pandora service running without servers ['.$nservers.'].');
if ($nservers >= 0) { if ($nservers >= 0) {
log_message($conf, 'LOG', 'Restarting Pandora service...'); log_message($conf, 'LOG', 'Restarting Pandora service...');
`$Pandora_Service restart-serer 2>/dev/null`; $control_command = "restart-server";
if ($OSNAME eq "freebsd") {
$control_command = "restart_server";
}
`$Pandora_Service $control_command 2>/dev/null`;
} }
} }
} }
@ -212,6 +230,7 @@ sub ha_keep_pandora_running($$) {
############################################################################### ###############################################################################
sub ha_update_server($$) { sub ha_update_server($$) {
my ($config, $dbh) = @_; my ($config, $dbh) = @_;
my $OSNAME = $^O;
my $repoServer = pandora_get_tconfig_token( my $repoServer = pandora_get_tconfig_token(
$dbh, 'remote_config', '/var/spool/pandora/data_in' $dbh, 'remote_config', '/var/spool/pandora/data_in'
@ -250,8 +269,11 @@ sub ha_update_server($$) {
# Restart service # Restart service
$config->{'pandora_service_cmd'} = 'service pandora_server' $config->{'pandora_service_cmd'} = 'service pandora_server'
unless defined($config->{'pandora_service_cmd'}); unless defined($config->{'pandora_service_cmd'});
my $control_command = "restart-server";
`$config->{'pandora_service_cmd'} restart-server 2>/dev/null`; if ($OSNAME eq "freebsd") {
$control_command = "restart_server";
}
`$config->{'pandora_service_cmd'} $control_command 2>/dev/null`;
`touch "$lockFile"`; `touch "$lockFile"`;
# After apply update, permission over files are changed, allow group to # After apply update, permission over files are changed, allow group to
@ -359,11 +381,17 @@ sub ha_main($) {
# Stop pandora server # Stop pandora server
################################################################################ ################################################################################
sub stop { sub stop {
my $OSNAME = $^O;
if ($Running == 1) { if ($Running == 1) {
$Running = 0; $Running = 0;
# cleanup and stop pandora_server # cleanup and stop pandora_server
print ">> stopping server...\n"; print ">> stopping server...\n";
`$Pandora_Service stop-server 2>/dev/null`; my $control_command = "stop-server";
if ($OSNAME eq "freebsd") {
$control_command = "stop_server";
}
`$Pandora_Service $control_command 2>/dev/null`;
} }
} }