Merge branch 'ent-improved-freebsd-support' into 'develop'
Improved daemon launcher and installer for FreeBSD. See merge request artica/pandorafms!4306
This commit is contained in:
commit
62be3f5830
|
@ -1,8 +1,8 @@
|
|||
#!/bin/sh
|
||||
|
||||
# **********************************************************************
|
||||
# Pandora FMS Server Daemon launcher for FreeBSD
|
||||
# (c) 2010 Junichi Satoh <junichi@rworks.jp>
|
||||
# Pandora FMS Server Daemon launcher through pandora_ha for FreeBSD
|
||||
# (c) 2010-2021 Junichi Satoh <junichi@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:
|
||||
# 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"
|
||||
|
||||
PATH=/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin
|
||||
|
||||
name="pandora_server"
|
||||
name="pandora_ha"
|
||||
rcvar=pandora_server_enable
|
||||
|
||||
: ${pandora_server_enable:=NO}
|
||||
: ${pandora_server_configfile:=/usr/local/etc/pandora/pandora_server.conf}
|
||||
|
||||
command=/usr/local/bin/${name}
|
||||
command_args="-D"
|
||||
command=/usr/local/bin/pandora_ha
|
||||
command_pandora=/usr/local/bin/pandora_server
|
||||
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_pandora=${_pidprefix_pandora}.pid
|
||||
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
|
||||
|
||||
if [ "$2" ]; then
|
||||
profile="$2"
|
||||
if [ "$pandora_server_profiles" ]; then
|
||||
pidfile="${_pidprefix}.${profile}.pid"
|
||||
eval pandora_server_configfile="\${pandora_server_${profile}_configfile:-}"
|
||||
if [ -z "$pandora_server_configfile" ]; then
|
||||
echo "You must define a configuration file (pandora_server_${profile}_configfile)"
|
||||
exit 1
|
||||
fi
|
||||
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
|
||||
control_pandora_server() {
|
||||
local name command pidfile
|
||||
name="pandora_server"
|
||||
command=$command_pandora
|
||||
pidfile=$pidfile_pandora
|
||||
pandora_server_flags="-D $pandora_server_flags -P $pidfile_pandora $pandora_server_configfile"
|
||||
pandora_arg=`echo $rc_arg | sed 's/_server//g'`
|
||||
unset "${pandora_arg}_cmd" "${pandora_arg}_precmd" "${pandora_arg}_postcmd"
|
||||
run_rc_command $pandora_arg
|
||||
}
|
||||
|
||||
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"
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
# **********************************************************************
|
||||
# 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
|
||||
|
||||
# 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
|
||||
|
||||
PATH=/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin
|
||||
: ${tentacle_server_enable="NO"}
|
||||
: ${tentacle_server_config="/usr/local/etc/tentacle/${name}.conf"}
|
||||
: ${tentacle_server_pidfile="/var/run/${name}.pid"}
|
||||
|
||||
command=/usr/local/bin/${name}
|
||||
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
|
||||
pidfile=/var/run/$name.pid
|
||||
pidfile=${tentacle_server_pidfile}
|
||||
|
||||
start_postcmd=start_postcmd
|
||||
stop_postcmd=stop_postcmd
|
||||
|
|
|
@ -407,6 +407,11 @@ install () {
|
|||
mv ${sh_script}.new $sh_script
|
||||
chmod a+x $sh_script
|
||||
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
|
||||
|
|
|
@ -159,6 +159,8 @@ sub help_screen {
|
|||
##############################################################################
|
||||
sub ha_keep_pandora_running($$) {
|
||||
my ($conf, $dbh) = @_;
|
||||
my $OSNAME = $^O;
|
||||
my $control_command;
|
||||
|
||||
$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'};
|
||||
|
||||
# Check if service is running
|
||||
my $pid = `$Pandora_Service status-server | awk '{print \$NF*1}' | tr -d '\.'`;
|
||||
$control_command = "status-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)) {
|
||||
# service running but not all components
|
||||
log_message($conf, 'LOG', 'Pandora service running but not all components.');
|
||||
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) {
|
||||
# service not running
|
||||
log_message($conf, 'LOG', 'Pandora service not running.');
|
||||
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
|
||||
&& $nservers == 0
|
||||
) {
|
||||
|
@ -202,7 +216,11 @@ sub ha_keep_pandora_running($$) {
|
|||
log_message($conf, 'LOG', 'Pandora service running without servers ['.$nservers.'].');
|
||||
if ($nservers >= 0) {
|
||||
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($$) {
|
||||
my ($config, $dbh) = @_;
|
||||
my $OSNAME = $^O;
|
||||
|
||||
my $repoServer = pandora_get_tconfig_token(
|
||||
$dbh, 'remote_config', '/var/spool/pandora/data_in'
|
||||
|
@ -250,8 +269,11 @@ sub ha_update_server($$) {
|
|||
# Restart service
|
||||
$config->{'pandora_service_cmd'} = 'service pandora_server'
|
||||
unless defined($config->{'pandora_service_cmd'});
|
||||
|
||||
`$config->{'pandora_service_cmd'} restart-server 2>/dev/null`;
|
||||
my $control_command = "restart-server";
|
||||
if ($OSNAME eq "freebsd") {
|
||||
$control_command = "restart_server";
|
||||
}
|
||||
`$config->{'pandora_service_cmd'} $control_command 2>/dev/null`;
|
||||
`touch "$lockFile"`;
|
||||
|
||||
# After apply update, permission over files are changed, allow group to
|
||||
|
@ -359,11 +381,17 @@ sub ha_main($) {
|
|||
# Stop pandora server
|
||||
################################################################################
|
||||
sub stop {
|
||||
my $OSNAME = $^O;
|
||||
|
||||
if ($Running == 1) {
|
||||
$Running = 0;
|
||||
# cleanup and stop pandora_server
|
||||
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`;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue