[packages/syslog-blacklist] add initscript

glen glen at pld-linux.org
Sun Oct 12 21:49:02 CEST 2014


commit a9593a925ff14de201314515fc2833310e5f6bfb
Author: Elan Ruusamäe <glen at delfi.ee>
Date:   Sun Oct 12 22:47:31 2014 +0300

    add initscript

 syslog-blacklist.init      | 109 +++++++++++++++++++++++++++++++++++++++++++++
 syslog-blacklist.spec      |  24 +++++++++-
 syslog-blacklist.sysconfig |   1 +
 3 files changed, 132 insertions(+), 2 deletions(-)
---
diff --git a/syslog-blacklist.spec b/syslog-blacklist.spec
index e49546d..7b5a2e6 100644
--- a/syslog-blacklist.spec
+++ b/syslog-blacklist.spec
@@ -8,18 +8,23 @@ Summary:	Intrusion Blocking with Perl and Ipset
 Name:		syslog-blacklist
 # from debian/changelog
 Version:	1.5
-Release:	0.3
+Release:	0.4
 License:	GPL v2+
 Group:		Applications/Networking
 # git clone http://bogeskov.dk/git/syslog-blacklist.git
 # tar --exclude-vcs -czf syslog-blacklist.tar.gz syslog-blacklist
 Source0:	%{name}.tar.gz
 # Source0-md5:	51258b2c1225333feb181e2ee4117716
+Source1:	%{name}.init
+Source2:	%{name}.sysconfig
 Patch0:		geoip.patch
 URL:		http://bogeskov.dk/Ipset.html
 BuildRequires:	dpkg
 BuildRequires:	rpm-perlprov >= 4.1-13
+BuildRequires:	rpmbuild(macros) >= 1.228
+Requires(post,preun):	/sbin/chkconfig
 Requires:	ipset
+Requires:	rc-scripts
 Suggests:	perl-Geo-IP
 BuildArch:	noarch
 BuildRoot:	%{tmpdir}/%{name}-%{version}-root-%(id -u -n)
@@ -40,19 +45,34 @@ test "$ver" = "%{version}"
 
 %install
 rm -rf $RPM_BUILD_ROOT
-install -d $RPM_BUILD_ROOT{%{_bindir},%{_sbindir},%{_sysconfdir},%{_mandir}}
+install -d $RPM_BUILD_ROOT{%{_bindir},%{_sbindir},%{_sysconfdir},%{_mandir},/etc/{sysconfig,rc.d/init.d}}
 cp -a usr/share/man/* $RPM_BUILD_ROOT%{_mandir}
 install -p usr/bin/syslog-inject $RPM_BUILD_ROOT%{_bindir}
 install -p usr/sbin/syslog-blacklist $RPM_BUILD_ROOT%{_sbindir}
 cp -p etc/syslog-blacklist.conf $RPM_BUILD_ROOT%{_sysconfdir}
 
+install -p %{SOURCE1} $RPM_BUILD_ROOT/etc/rc.d/init.d/%{name}
+cp -p %{SOURCE2} $RPM_BUILD_ROOT/etc/sysconfig/%{name}
+
 %clean
 rm -rf $RPM_BUILD_ROOT
 
+%post
+/sbin/chkconfig --add %{name}
+%service %{name} restart
+
+%preun
+if [ "$1" = "0" ]; then
+	%service -q %{name} stop
+	/sbin/chkconfig --del %{name}
+fi
+
 %files
 %defattr(644,root,root,755)
 %doc copyright
 %config(noreplace) %verify(not md5 mtime size) %{_sysconfdir}/syslog-blacklist.conf
+%config(noreplace) %verify(not md5 mtime size) /etc/sysconfig/syslog-blacklist
+%attr(754,root,root) /etc/rc.d/init.d/syslog-blacklist
 %attr(755,root,root) %{_bindir}/syslog-inject
 %attr(755,root,root) %{_sbindir}/syslog-blacklist
 %{_mandir}/man1/syslog-blacklist.1*
diff --git a/syslog-blacklist.init b/syslog-blacklist.init
new file mode 100755
index 0000000..5b5c22a
--- /dev/null
+++ b/syslog-blacklist.init
@@ -0,0 +1,109 @@
+#!/bin/sh
+#
+# syslog-blacklist	syslog-blacklist startup script
+#
+# chkconfig:	345 20 80
+# description:	This script starts the syslog-blacklist daemon.
+# processname:	syslog-blacklist
+
+# Source function library
+. /etc/rc.d/init.d/functions
+
+# Get network config
+. /etc/sysconfig/network
+
+# Check that networking is up.
+if is_yes "${NETWORKING}"; then
+	if [ ! -f /var/lock/subsys/network -a "$1" != stop -a "$1" != status ]; then
+		msg_network_down "Syslog blacklist"
+		exit 1
+	fi
+else
+	exit 0
+fi
+
+# Set defaults
+OPTIONS=""
+
+# Get service config - may override defaults
+[ -f /etc/sysconfig/syslog-blacklist ] && . /etc/sysconfig/syslog-blacklist
+
+pidfile="/var/run/syslog-blacklist.pid"
+
+start() {
+	# Check if the service is already running?
+	if [ -f /var/lock/subsys/syslog-blacklist ]; then
+		msg_already_running "Syslog blacklist"
+		return
+	fi
+
+	msg_starting "Syslog blacklist"
+	daemon /usr/sbin/syslog-blacklist --pidfile=$pidfile $OPTIONS
+	RETVAL=$?
+	[ $RETVAL -eq 0 ] && touch /var/lock/subsys/syslog-blacklist
+}
+
+stop() {
+	if [ ! -f /var/lock/subsys/syslog-blacklist ]; then
+		msg_not_running "Syslog blacklist"
+		return
+	fi
+
+	# Stop daemons.
+	msg_stopping "Syslog blacklist"
+	killproc --pidfile $pidfile syslog-blacklist -TERM
+	rm -f /var/lock/subsys/syslog-blacklist
+}
+
+reload() {
+	if [ ! -f /var/lock/subsys/syslog-blacklist ]; then
+		msg_not_running "Syslog blacklist"
+		RETVAL=7
+		return
+	fi
+
+	msg_reloading "Syslog blacklist"
+	killproc --pidfile $pidfile syslog-blacklist -HUP
+	RETVAL=$?
+}
+
+condrestart() {
+	if [ ! -f /var/lock/subsys/syslog-blacklist ]; then
+		msg_not_running "Syslog blacklist"
+		RETVAL=$1
+		return
+	fi
+
+	stop
+	start
+}
+
+RETVAL=0
+# See how we were called.
+case "$1" in
+  start)
+	start
+	;;
+  stop)
+	stop
+	;;
+  restart)
+	stop
+	start
+	;;
+  try-restart)
+	condrestart 0
+	;;
+  reload|force-reload)
+	reload
+	;;
+  status)
+	status --pidfile $pidfile syslog-blacklist
+	RETVAL=$?
+	;;
+  *)
+	msg_usage "$0 {start|stop|restart|try-restart|reload|force-reload|status}"
+	exit 3
+esac
+
+exit $RETVAL
diff --git a/syslog-blacklist.sysconfig b/syslog-blacklist.sysconfig
new file mode 100644
index 0000000..e34976a
--- /dev/null
+++ b/syslog-blacklist.sysconfig
@@ -0,0 +1 @@
+OPTIONS="--blocked=8h"
================================================================

---- gitweb:

http://git.pld-linux.org/gitweb.cgi/packages/syslog-blacklist.git/commitdiff/a9593a925ff14de201314515fc2833310e5f6bfb



More information about the pld-cvs-commit mailing list