[packages/swatch] rel 2; added extensive systemd support

mmazur mmazur at pld-linux.org
Wed Feb 4 11:46:35 CET 2015


commit 7dfa6bcf596225a4e874309f1c1a8e2b7286b439
Author: Mariusz Mazur <mmazur at axeos.com>
Date:   Wed Feb 4 10:40:11 2015 +0000

    rel 2; added extensive systemd support

 sample.conf              | 12 ++++++++++++
 sample.poststop          | 11 +++++++++++
 sample.prestart          | 11 +++++++++++
 swatchrc => sample.rc    |  0
 swatch-service-generator | 21 +++++++++++++++++++++
 swatch.spec              | 37 ++++++++++++++++++++++++++++++++-----
 swatch.sysconfig         |  3 +++
 swatch.target            |  5 +++++
 swatch at .service          | 16 ++++++++++++++++
 9 files changed, 111 insertions(+), 5 deletions(-)
---
diff --git a/swatch.spec b/swatch.spec
index 0e88cc3..7be6aaa 100644
--- a/swatch.spec
+++ b/swatch.spec
@@ -7,12 +7,19 @@ Summary:	A utility for monitoring system logs files
 Summary(pl.UTF-8):	Narzędzie do monitorowania logów systemowych
 Name:		swatch
 Version:	3.2.3
-Release:	1
+Release:	2
 License:	GPL v2+
 Group:		Applications/System
 Source0:	http://dl.sourceforge.net/swatch/%{name}-%{version}.tar.gz
 # Source0-md5:	1162f1024cf07fc750ed4960d61ac4e8
-Source1:	%{name}rc
+Source1:    sample.rc
+Source2:    sample.conf
+Source3:    sample.prestart
+Source4:    sample.poststop
+Source5:    swatch.sysconfig
+Source6:    swatch-service-generator
+Source7:    swatch.target
+Source8:    swatch at .service
 URL:		http://swatch.sourceforge.net/
 BuildRequires:	perl-base
 BuildRequires:	perl-devel
@@ -50,8 +57,21 @@ skryptu itp.) w zależności od zawartości logów.
 
 %install
 rm -rf $RPM_BUILD_ROOT
-install -d $RPM_BUILD_ROOT%{_examplesdir}/%{name}-%{version}
-install %{SOURCE1} $RPM_BUILD_ROOT%{_examplesdir}/%{name}-%{version}
+install -d $RPM_BUILD_ROOT%{_sysconfdir}/%{name} \
+    $RPM_BUILD_ROOT/etc/sysconfig \
+    $RPM_BUILD_ROOT{%{systemdtmpfilesdir},%{systemdunitdir}} \
+    $RPM_BUILD_ROOT/lib/systemd/system-generators
+
+install %{SOURCE1} $RPM_BUILD_ROOT%{_sysconfdir}/%{name}/sample.rc
+install %{SOURCE2} $RPM_BUILD_ROOT%{_sysconfdir}/%{name}/sample.conf
+install %{SOURCE3} $RPM_BUILD_ROOT%{_sysconfdir}/%{name}/sample.prestart
+install %{SOURCE4} $RPM_BUILD_ROOT%{_sysconfdir}/%{name}/sample.poststop
+install %{SOURCE5} $RPM_BUILD_ROOT/etc/sysconfig/%{name}
+
+install -p %{SOURCE6} $RPM_BUILD_ROOT/lib/systemd/system-generators/%{name}-service-generator
+install -p %{SOURCE7} $RPM_BUILD_ROOT%{systemdunitdir}/%{name}.target
+install -p %{SOURCE8} $RPM_BUILD_ROOT%{systemdunitdir}/%{name}@.service
+
 
 %{__make} install \
 	DESTDIR=$RPM_BUILD_ROOT
@@ -64,6 +84,14 @@ rm -rf $RPM_BUILD_ROOT
 %files
 %defattr(644,root,root,755)
 %doc CHANGES COPYRIGHT KNOWN_BUGS README examples
+%config(noreplace) %verify(not md5 mtime size) /etc/sysconfig/%{name}
+%attr(755,root,root) /lib/systemd/system-generators/%{name}-service-generator
+%{systemdunitdir}/%{name}.target
+%{systemdunitdir}/%{name}@.service
+%attr(770,root,root) %dir %{_sysconfdir}/%{name}
+%{_sysconfdir}/%{name}/sample.conf
+%{_sysconfdir}/%{name}/sample.rc
+%attr(755,root,root) %{_sysconfdir}/%{name}/sample.p*
 %attr(755,root,root) %{_bindir}/*
 %{_mandir}/man1/*
 %{_mandir}/man3/*
@@ -71,4 +99,3 @@ rm -rf $RPM_BUILD_ROOT
 %dir %{perl_vendorlib}/auto/Swatch
 %dir %{perl_vendorlib}/auto/Swatch/Actions
 %{perl_vendorlib}/auto/Swatch/Actions/autosplit.ix
-%{_examplesdir}/%{name}-%{version}
diff --git a/sample.conf b/sample.conf
new file mode 100644
index 0000000..a52bf94
--- /dev/null
+++ b/sample.conf
@@ -0,0 +1,12 @@
+# This files controls how a single instance of swatch is run
+# You run an instance by doing systemctl start/stop/restart swatch at sample
+#
+# Some default values you can override:
+#RC_FILE=/etc/swatch/sample.rc
+#PRESTART_EXEC=/etc/swatch/sample.prestart
+#POSTSTOP_EXEC=/etc/swatch/sample.poststop
+
+# Consult man page of 'swatch'
+# You need to at least specify something to monitor
+SWATCH_OPTS="--tail-file=/var/log/syslog"
+
diff --git a/sample.poststop b/sample.poststop
new file mode 100644
index 0000000..da6779e
--- /dev/null
+++ b/sample.poststop
@@ -0,0 +1,11 @@
+#!/bin/sh
+# This file is run after a swatch instance stops. If you need a place to put
+# cleanup code, this file is it.
+# Existence of this file is optional. If it doesn't exist, executing it won't
+# be attempted.
+# However if it does exist, it needs to be a proper executable file (+x set)
+# and it needs to exit without errors. If it exits with errors, systemd
+# will treat this as an error.
+
+logger "poststop run"
+
diff --git a/sample.prestart b/sample.prestart
new file mode 100644
index 0000000..58beb0c
--- /dev/null
+++ b/sample.prestart
@@ -0,0 +1,11 @@
+#!/bin/sh
+# This file is run before a swatch instance starts. If you need a place to put
+# initialization code, this file is it.
+# Existence of this file is optional. If it doesn't exist, executing it won't
+# be attempted.
+# However if it does exist, it needs to be a proper executable file (+x set)
+# and it needs to exit without errors. If it exits with errors, systemd
+# will treat this as an error and refuse to run the swatch binary.
+
+logger "prestart run"
+
diff --git a/swatchrc b/sample.rc
similarity index 100%
rename from swatchrc
rename to sample.rc
diff --git a/swatch-service-generator b/swatch-service-generator
new file mode 100644
index 0000000..e7c3d97
--- /dev/null
+++ b/swatch-service-generator
@@ -0,0 +1,21 @@
+#!/bin/sh
+
+destunitdir=${1:-/tmp}
+
+# Do nothing if target is disabled
+[ -e /etc/systemd/system/multi-user.target.wants/swatch.target ] || exit 0
+
+[ -f /etc/sysconfig/swatch ] && . /etc/sysconfig/swatch
+
+if [ -d $destunitdir/swatch.target.wants ]; then
+	rm -f $destunitdir/swatch.target.wants/swatch@*.service
+else
+	mkdir -p $destunitdir/swatch.target.wants
+fi
+
+for name in $INSTANCES; do
+	[ -L $destunitdir/swatch.target.wants/swatch at name.service ] && \
+		continue
+	ln -s /lib/systemd/system/swatch at .service \
+		$destunitdir/swatch.target.wants/swatch at name.service
+done
diff --git a/swatch.sysconfig b/swatch.sysconfig
new file mode 100644
index 0000000..8126a98
--- /dev/null
+++ b/swatch.sysconfig
@@ -0,0 +1,3 @@
+# List of swatch instances to run
+
+#INSTANCES=
diff --git a/swatch.target b/swatch.target
new file mode 100644
index 0000000..c16a7ed
--- /dev/null
+++ b/swatch.target
@@ -0,0 +1,5 @@
+[Unit]
+Description=Start swatch sessions
+
+[Install]
+WantedBy=multi-user.target
diff --git a/swatch at .service b/swatch at .service
new file mode 100644
index 0000000..c55b955
--- /dev/null
+++ b/swatch at .service
@@ -0,0 +1,16 @@
+[Unit]
+Description=Swatch instance %I
+Requires=swatch.target
+After=swatch.target
+
+[Service]
+Type=simple
+Environment="RC_FILE=/etc/swatch/%i.rc" "PRESTART_EXEC=/etc/swatch/%i.prestart" "POSTSTOP_EXEC=/etc/swatch/%i.poststop"
+EnvironmentFile=/etc/swatch/%i.conf
+ExecStartPre=/bin/sh -c '[ ! -e ${PRESTART_EXEC} ] && exit 0; ${PRESTART_EXEC}'
+ExecStopPost=/bin/sh -c '[ ! -e ${POSTSTOP_EXEC} ] && exit 0; ${POSTSTOP_EXEC}'
+ExecStart=/usr/bin/swatch --config-file ${RC_FILE} $SWATCH_OPTS
+ExecReload=/bin/kill -HUP $MAINPID
+
+[Install]
+WantedBy=swatch.target
================================================================

---- gitweb:

http://git.pld-linux.org/gitweb.cgi/packages/swatch.git/commitdiff/7dfa6bcf596225a4e874309f1c1a8e2b7286b439



More information about the pld-cvs-commit mailing list