Przeglądaj źródła

Minor changes to startup files and added uninstall script

John C. Frickson 9 lat temu
rodzic
commit
b029fa3102

+ 6 - 3
.gitignore

@@ -4,6 +4,10 @@ config.status
 include/config.h
 include/dh.h
 nrpe.spec
+paths
+uninstall
+.cproject
+.project
 package/solaris/Makefile
 sample-config/nrpe.cfg
 src/Makefile
@@ -11,15 +15,14 @@ src/check_nrpe
 src/nrpe
 autom4te.cache/
 nbproject/
-.cproject
-.project
 .settings/
-paths
 startup/bsd-init
 startup/debian-init
 startup/default-inetd
 startup/default-init
 startup/default-service
+startup/default-socket
+startup/default-socket-svc
 startup/default-xinetd
 startup/mac-org.nagios.PKG_NAME.plist
 startup/openrc-conf

+ 3 - 1
configure

@@ -4823,7 +4823,7 @@ fi
 
 ac_config_headers="$ac_config_headers include/config.h"
 
-ac_config_files="$ac_config_files Makefile src/Makefile package/solaris/Makefile nrpe.spec sample-config/nrpe.cfg startup/bsd-init startup/debian-init startup/default-init startup/default-inetd startup/default-service startup/default-socket startup/default-xinetd startup/mac-org.nagios.PKG_NAME.plist startup/openrc-conf startup/openrc-init startup/solaris-PKG_NAME.xml startup/upstart-init"
+ac_config_files="$ac_config_files Makefile src/Makefile package/solaris/Makefile nrpe.spec uninstall sample-config/nrpe.cfg startup/bsd-init startup/debian-init startup/default-init startup/default-inetd startup/default-service startup/default-socket startup/default-socket-svc startup/default-xinetd startup/mac-org.nagios.PKG_NAME.plist startup/openrc-conf startup/openrc-init startup/solaris-PKG_NAME.xml startup/upstart-init"
 
 
 #sample-config/debian-nrpe-inetd
@@ -8062,6 +8062,7 @@ do
     "src/Makefile") CONFIG_FILES="$CONFIG_FILES src/Makefile" ;;
     "package/solaris/Makefile") CONFIG_FILES="$CONFIG_FILES package/solaris/Makefile" ;;
     "nrpe.spec") CONFIG_FILES="$CONFIG_FILES nrpe.spec" ;;
+    "uninstall") CONFIG_FILES="$CONFIG_FILES uninstall" ;;
     "sample-config/nrpe.cfg") CONFIG_FILES="$CONFIG_FILES sample-config/nrpe.cfg" ;;
     "startup/bsd-init") CONFIG_FILES="$CONFIG_FILES startup/bsd-init" ;;
     "startup/debian-init") CONFIG_FILES="$CONFIG_FILES startup/debian-init" ;;
@@ -8069,6 +8070,7 @@ do
     "startup/default-inetd") CONFIG_FILES="$CONFIG_FILES startup/default-inetd" ;;
     "startup/default-service") CONFIG_FILES="$CONFIG_FILES startup/default-service" ;;
     "startup/default-socket") CONFIG_FILES="$CONFIG_FILES startup/default-socket" ;;
+    "startup/default-socket-svc") CONFIG_FILES="$CONFIG_FILES startup/default-socket-svc" ;;
     "startup/default-xinetd") CONFIG_FILES="$CONFIG_FILES startup/default-xinetd" ;;
     "startup/mac-org.nagios.PKG_NAME.plist") CONFIG_FILES="$CONFIG_FILES startup/mac-org.nagios.PKG_NAME.plist" ;;
     "startup/openrc-conf") CONFIG_FILES="$CONFIG_FILES startup/openrc-conf" ;;

+ 2 - 0
configure.ac

@@ -99,6 +99,7 @@ AC_CONFIG_FILES([Makefile
 	src/Makefile
 	package/solaris/Makefile
 	nrpe.spec
+	uninstall
 	sample-config/nrpe.cfg
 	startup/bsd-init
 	startup/debian-init
@@ -106,6 +107,7 @@ AC_CONFIG_FILES([Makefile
 	startup/default-inetd
 	startup/default-service
 	startup/default-socket
+	startup/default-socket-svc
 	startup/default-xinetd
 	startup/mac-org.nagios.PKG_NAME.plist
 	startup/openrc-conf

+ 6 - 3
src/Makefile.in

@@ -65,19 +65,22 @@ install:
 	$(MAKE) install-plugin
 	$(MAKE) install-daemon
 
-install-plugin:
+install-plugin: install-uninstall
 	$(INSTALL) -m 775 $(NAGIOS_INSTALL_OPTS) -d $(LIBEXECDIR)
 	$(INSTALL) -m 775 $(NAGIOS_INSTALL_OPTS) -d $(PLUGINSDIR)
 	$(INSTALL) -m 775 $(NAGIOS_INSTALL_OPTS) check_nrpe $(PLUGINSDIR)
 
-install-daemon:
-	$(INSTALL) -m 755 -d $(SBINDIR)
+install-daemon: install-uninstall
 	$(INSTALL) -m 755 nrpe $(SBINDIR)
 	@if ! test -d "$PIDDIR" ; then \
 		echo $(INSTALL) -m 755 $(NRPE_INSTALL_OPTS) -d $(PIDDIR); \
 		$(INSTALL) -m 755 $(NRPE_INSTALL_OPTS) -d $(PIDDIR); \
 	fi
 
+install-uninstall:
+	$(INSTALL) -m 755 -d $(SBINDIR)
+	$(INSTALL) -m 755 ../uninstall $(SBINDIR)/nrpe-uninstall
+
 clean:
 	rm -f core nrpe check_nrpe $(SNPRINTF_O)
 	rm -f *~ */*~

+ 1 - 1
startup/default-service.in

@@ -13,7 +13,7 @@ Type=simple
 Restart=on-abort
 PIDFile=@piddir@/nrpe.pid
 RuntimeDirectory=nrpe
-RuntimeMode=0755
+RuntimeDirectoryMode=0755
 ExecStart=@sbindir@/nrpe -c @pkgsysconfdir@/nrpe.cfg -f
 ExecStopPost=/bin/rm -f @piddir@/nrpe.pid
 TimeoutStopSec=60

+ 16 - 0
startup/default-socket-svc.in

@@ -0,0 +1,16 @@
+[Unit]
+Description=Nagios Remote Program Executor
+Documentation=http://www.nagios.org/documentation
+After=var-run.mount nss-lookup.target network.target local-fs.target time-sync.target
+
+[Service]
+Restart=on-failure
+ExecStart=@sbindir@/nrpe -c @pkgsysconfdir@/nrpe.cfg -f
+KillMode=process
+User=@nagios_user@
+Group=@nagios_group@
+PrivateTmp=true
+OOMScoreAdjust=-500
+
+[Install]
+WantedBy=multi-user.target

+ 6 - 12
startup/default-socket.in

@@ -1,18 +1,12 @@
 [Unit]
 Description=Nagios Remote Program Executor
 Documentation=http://www.nagios.org/documentation
-After=var-run.mount nss-lookup.target network.target local-fs.target time-sync.target
-Before=getty@tty1.service plymouth-quit.service xdm.service
+Before=nrpe.service
 Conflicts=nrpe.service
 
-[Install]
-WantedBy=multi-user.target
+[Socket]
+ListenStream=@nrpe_port@
+Accept=yes
 
-[Service]
-Accept=true
-ExecStart=@sbindir@/nrpe -c @pkgsysconfdir@/nrpe.cfg -i
-TimeoutStopSec=60
-User=@nagios_user@
-Group=@nagios_group@
-PrivateTmp=true
-OOMScoreAdjust=-500
+[Install]
+WantedBy=sockets.target

+ 1 - 0
startup/mac-org.nagios.PKG_NAME.plist.in

@@ -14,6 +14,7 @@
 	<array>
 		<string>-c</string>
 		<string>@pkgsysconfdir@/nrpe.cfg</string>
+		<string>-i</string>
 	</array>
 	<key>KeepAlive</key>
 	<dict>

+ 1 - 1
startup/openrc-init.in

@@ -31,7 +31,7 @@ start() {
 	# Make sure we have a sane current directory
 	cd /
 	start-stop-daemon --start --exec $NRPE_BIN --pidfile $PID_FILE \
-		-- -c $NRPE_CFG -d $NRPE_OPTS
+		-- -c $NRPE_CFG -f $NRPE_OPTS
 	eend $?
 }
 

+ 0 - 20
startup/upstart-init

@@ -1,20 +0,0 @@
-# nrpe - the Nagios Remote Plugin Executor
-#
-# nrpe is a program that runs plugins on this host
-# and reports the results back to a nagios server
-#
-# Copyright (c) 2016 Nagios(R) Core(TM) Development Team
-
-description		"the Nagios Remote Plugin Executor"
-
-oom score -800
-setgid nagios
-setuid nagios
-
-start on (local-filesystems and net-device-up IFACE!=lo)
-stop on runlevel [!2345]
-
-expect daemon
-respawn
-
-exec /usr/sbin/nrpe -c /etc/nagios/nrpe.cfg -d

+ 1 - 1
startup/upstart-init.in

@@ -17,4 +17,4 @@ stop on runlevel [!2345]
 expect daemon
 respawn
 
-exec @sbindir@/nrpe -c @pkgsysconfdir@/nrpe.cfg -d
+exec @sbindir@/nrpe -c @pkgsysconfdir@/nrpe.cfg -f

+ 222 - 0
uninstall.in

@@ -0,0 +1,222 @@
+#!/bin/sh
+
+# Initialize variables
+quiet=0
+prompt=0
+verb=0
+progs=0
+config=0
+start=0
+force="-f"
+redir="2>/dev/null"
+
+# Set file and path names
+NAME=@PKG_NAME@
+SBINDIR=@sbindir@
+LIBEXECDIR=@libexecdir@
+PLUGINSDIR=@pluginsdir@
+PIDDIR=@piddir@
+CFGDIR=@pkgsysconfdir@
+INIT_TYPE=@init_type@
+INIT_DIR=@initdir@
+INIT_FILE=@initname@
+INETD_TYPE=@inetd_type@
+INETD_DIR=@inetddir@
+INETD_FILE=@inetdname@
+SRC_INETD=@src_inetd@
+SRC_INIT=@src_init@
+
+
+# Display usage message
+usage () {
+	echo "Usage: $0 [-q] [-p] [-v] progs|config|startup|all"
+	echo "-q       Do not print what is happening"
+	echo "-p       Prompt for each action"
+	echo "-v       Be a little more verbose about what is happening"
+	echo "progs    Delete the program files"
+	echo "config   Delete configuration file(s)"
+	echo "startup  Delete startup files (inetd, init, etc.)"
+	echo "         Delete startup files (inetd, init, etc.)"
+	exit 1
+}
+
+get_opts () {
+	while test $# -gt 0 ; do
+		arg=$1
+		shift
+		case "$arg" in
+			-q)			quiet=1		;;
+			-p)			prompt=1	;;
+			progs)		progs=1		;;
+			config)		config=1	;;
+			startup)	start=1		;;
+			-v)			verb=1; force=""; redir="" 	;;
+			all)		progs=1; config=1; start=1	;;
+			*)			echo "Invalid argument: $arg";	usage	;;
+		esac
+	done
+
+	if test $prompt -eq 1 -a $quiet -eq 1 ; then
+		echo "The -p and -q flags are mutually exclusive"
+		echo Please specify one or the other
+		exit 1
+	fi
+	if test $verb -eq 1 -a $quiet -eq 1 ; then
+		echo "The -v and -q flags are mutually exclusive"
+		echo Please specify one or the other
+		exit 1
+	fi
+	if test $progs -eq 0 -a $config -eq 0 ; then
+		usage
+	fi
+}
+
+prt_msg () {
+	if test $quiet -eq 1 ; then
+		return 0
+	fi
+
+	if test $1 -eq 1 -a $verb -eq 0 -a $prompt -eq 0 ; then
+		return 0
+	fi
+	shift
+
+	if test $1 -eq 1 -a $prompt -eq 1 ; then
+		shift
+		echo -n "    $*"
+		echo -n "? [Y|n] "
+		read yn
+		if test "x$yn" = x -o x$yn = xy -o x$yn = xY ; then
+			return 0
+		else
+			return 1
+		fi
+	fi
+
+	shift
+	echo "    $*"
+	return 0
+}
+
+rm_progs () {
+	if test -f "$PLUGINSDIR/check_nrpe" ; then
+		prt_msg 0 1 "Delete $PLUGINSDIR/check_nrpe" && {
+			rm $force "$PLUGINSDIR/check_nrpe"
+			prt_msg 1 0 "Remove directory $PLUGINSDIR"
+			rmdir "$PLUGINSDIR" $redir
+			prt_msg 1 0 "Remove directory $LIBEXECDIR"
+			rmdir "$LIBEXECDIR" $redir
+		}
+	fi
+
+	if test -f "$SBINDIR/$NAME" ; then
+		prt_msg 0 1 "Delete $SBINDIR/$NAME" && {
+			rm $force "$SBINDIR/$NAME"
+		}
+	fi
+
+    if test -d "$PIDDIR" ; then
+		prt_msg 0 1 "Remove directory $PIDDIR" && {
+	        rmdir "$PIDDIR" $redir
+		}
+    fi
+}
+
+rm_startup () {
+	if test "$SRC_INETD" != unknown; then
+		if test "$INETD_TYPE" = inetd; then
+			rc=`grep -E -q "^\W*@PKG_NAME@\s+" "$INETD_DIR/$INETD_FILE"`
+			if test $rc -eq 0; then
+				prt_msg 0 1 "Remove entries from $INETD_DIR/$INETD_FILE" && {
+					prt_msg 1 0 "Creating temp file: $INETD_DIR/$INETD_FILE.$NAME.unin"
+					grep -v -q "\W*@PKG_NAME@\s+" "$INETD_DIR/$INETD_FILE" > "$INETD_DIR/$INETD_FILE.$NAME.unin"
+					prt_msg 1 0 "Renaming original to: $INETD_DIR/$INETD_FILE.$NAME_save"
+					mv "$INETD_DIR/$INETD_FILE" "$INETD_DIR/$INETD_FILE.$NAME_save"
+					prt_msg 1 0 "Renaming $INETD_DIR/$INETD_FILE.unin to $INETD_DIR/$INETD_FILE"
+					mv "$INETD_DIR/$INETD_FILE.unin" "$INETD_DIR/$INETD_FILE"
+					prt_msg 0 0 "Old $INETD_DIR/$INETD_FILE saved as $INETD_DIR/$INETD_FILE.$NAME_save"
+				}
+			fi
+		else
+			if test "$INETD_TYPE" != xinetd; then
+				prt_msg 0 1 "Stop and disable $NAME" && {
+					case "$INETD_TYPE in
+					systemd)
+						systemctl stop $NAME; systemctl disable $NAME
+						;;
+					upstart)
+						stop $NAME
+						;;
+					launchd)
+						launchctl unload $INETD_FILE; launchctl remove $INETD_FILE;
+						;;
+					smf*)
+						svcadm disable -s $NAME
+						;;
+					esac
+				}
+			fi
+			prt_msg 0 1 "Delete $INETD_DIR/$INETD_FILE" && {
+				rm $force "$INETD_DIR/$INETD_FILE"
+				if test "$INETD_TYPE" = systemd; then
+					INETD_FILE=`echo "$INETD_FILE" | sed -e 's/socket$/service/'`
+					prt_msg 0 1 "Delete $INETD_DIR/$INETD_FILE" && {
+						rm $force "$INETD_DIR/$INETD_FILE"
+					}
+				fi
+			}
+		fi
+	fi
+
+	if test "$SRC_INIT" != unknown; then
+		prt_msg 0 1 "Stop and disable $NAME" && {
+			case "$INIT_TYPE in
+			systemd)
+				systemctl stop $NAME; systemctl disable $NAME
+				;;
+			upstart)
+				stop $NAME
+				;;
+			launchd)
+				launchctl unload $INIT_FILE; launchctl remove $INIT_FILE;
+				;;
+			*bsd)
+				if test -x $INIT_DIR/$INIT_FILE ; then
+					$INIT_DIR/$INIT_FILE stop
+				fi
+				chmod 0644 $INIT_DIR/$INIT_FILE
+				;;
+			openrc|gentoo)
+				/sbin/start-stop-daemon --stop $NAME
+				/sbin/rc-update del $NAME
+				;;
+			smf*)
+				svcadm disable -s $NAME
+				;;
+			sysv)
+				service stop $NAME; chkconfig --del $NAME
+				;;
+			esac
+		}
+		prt_msg 0 1 "Delete $INETD_DIR/$INIT_FILE" && {
+			rm $force "$INIT_DIR/$INIT_FILE"
+		}
+	fi
+}
+
+rm_config () {
+	prt_msg 0 1 "Delete $CFGDIR/$NAME.cfg" || return
+	rm $force "$CFGDIR/$NAME.cfg"
+	prt_msg 1 0 "Removing directory $CFGDIR"
+	rm $force "$CFGDIR"
+}
+
+get_opts $@
+
+echo "* * * Uninstall Starting * * *"
+
+if test $progs -eq 1 ;	then rm_progs;		fi
+if test $start -eq 1 ;	then rm_startup;	fi
+if test $config -eq 1 ;	then rm_config;		fi
+
+echo "* * * Uninstall Complete * * *"