[packages/qemu] - rel 2; add init.d script and logrotate config for qemu guest agent

arekm arekm at pld-linux.org
Tue Aug 20 12:20:02 CEST 2019


commit ccb0f0ea96ede99bb7d577a06ac18c2d29981526
Author: Arkadiusz Miśkiewicz <arekm at maven.pl>
Date:   Tue Aug 20 12:19:52 2019 +0200

    - rel 2; add init.d script and logrotate config for qemu guest agent

 qemu-guest-agent.init      | 124 +++++++++++++++++++++++++++++++++++++++++++++
 qemu-guest-agent.logrotate |   6 +++
 qemu.spec                  |  17 ++++++-
 3 files changed, 145 insertions(+), 2 deletions(-)
---
diff --git a/qemu.spec b/qemu.spec
index 3afd75b..836bde3 100644
--- a/qemu.spec
+++ b/qemu.spec
@@ -35,7 +35,7 @@ Summary:	QEMU CPU Emulator
 Summary(pl.UTF-8):	QEMU - emulator procesora
 Name:		qemu
 Version:	4.1.0
-Release:	1
+Release:	2
 License:	GPL v2, BSD (edk2 firmware files)
 Group:		Applications/Emulators
 Source0:	http://wiki.qemu-project.org/download/%{name}-%{version}.tar.xz
@@ -54,6 +54,8 @@ Source9:	ksmtuned
 Source10:	ksmtuned.conf
 Source11:	%{name}-guest-agent.service
 Source12:	99-%{name}-guest-agent.rules
+Source13:	%{name}-guest-agent.init
+Source14:	%{name}-guest-agent.logrotate
 Patch0:		%{name}-cflags.patch
 Patch1:		%{name}-whitelist.patch
 Patch2:		%{name}-user-execve.patch
@@ -931,7 +933,7 @@ build static \
 %install
 rm -rf $RPM_BUILD_ROOT
 install -d $RPM_BUILD_ROOT{%{systemdunitdir},/usr/lib/binfmt.d} \
-	$RPM_BUILD_ROOT/etc/{qemu,sysconfig,udev/rules.d,modules-load.d} \
+	$RPM_BUILD_ROOT/etc/{qemu,sysconfig,udev/rules.d,modules-load.d,rc.d/init.d,logrotate.d} \
 	$RPM_BUILD_ROOT{%{_sysconfdir}/sasl,%{_sbindir}}
 
 %if %{with user_static}
@@ -978,6 +980,9 @@ install -p %{SOURCE10} $RPM_BUILD_ROOT%{_sysconfdir}/ksmtuned.conf
 install -p %{SOURCE11} $RPM_BUILD_ROOT%{systemdunitdir}
 install -p %{SOURCE12} $RPM_BUILD_ROOT%{_sysconfdir}/udev/rules.d
 
+install -p %{SOURCE13} $RPM_BUILD_ROOT/etc/rc.d/init.d/qemu-ga
+install -p %{SOURCE14} $RPM_BUILD_ROOT/etc/logrotate.d/qemu-ga
+
 # Install binfmt
 for i in dummy \
 %ifnarch %{ix86} %{x8664} x32
@@ -1095,9 +1100,15 @@ fi
 %systemd_service_restart systemd-binfmt.service
 
 %post guest-agent
+/sbin/chkconfig --add qemu-ga
+%service qemu-ga restart "qemu-ga"
 %systemd_reload
 
 %preun guest-agent
+if [ "$1" = "0" ]; then
+  %service qemu-ga stop
+  /sbin/chkconfig --del qemu-ga
+fi
 %systemd_preun qemu-guest-agent.service
 
 %postun guest-agent
@@ -1416,6 +1427,8 @@ fi
 %defattr(644,root,root,755)
 %config(noreplace) %verify(not md5 mtime size) /etc/udev/rules.d/99-qemu-guest-agent.rules
 %{systemdunitdir}/qemu-guest-agent.service
+%attr(754,root,root) /etc/rc.d/init.d/qemu-ga
+%attr(640,root,root) %config(noreplace) %verify(not md5 mtime size) /etc/logrotate.d/qemu-ga
 %attr(755,root,root) %{_bindir}/qemu-ga
 %{_mandir}/man7/qemu-ga-ref.7*
 %{_mandir}/man8/qemu-ga.8*
diff --git a/qemu-guest-agent.init b/qemu-guest-agent.init
new file mode 100755
index 0000000..2ca1ec5
--- /dev/null
+++ b/qemu-guest-agent.init
@@ -0,0 +1,124 @@
+#!/bin/sh
+#
+# qemu-ga	qemu-ga	QEMU Guest Agent
+#
+# chkconfig:	345 12 88
+#
+# description:	qemu-ga QEMU Guest Agent
+
+# Source function library
+. /etc/rc.d/init.d/functions
+
+# Get service config - may override defaults
+[ -f /etc/sysconfig/qemu-ga ] && . /etc/sysconfig/qemu-ga
+
+pidfile="/var/run/qemu-ga.pid"
+
+# configtest itself
+# must return non-zero if check failed
+# output is discarded if checkconfig is ran without details
+configtest() {
+	/usr/bin/qemu-ga -D
+	return $?
+}
+
+# wrapper for configtest
+checkconfig() {
+	local details=${1:-0}
+
+	if [ $details = 1 ]; then
+		# run config test and display report (status action)
+		show "Checking %s configuration" "qemu-ga"; busy
+		local out
+		out=$(configtest 2>&1)
+		RETVAL=$?
+		if [ $RETVAL = 0 ]; then
+			ok
+		else
+			fail
+		fi
+		[ "$out" ] && echo >&2 "$out"
+	else
+		# run config test and abort with nice message if failed
+		# (for actions checking status before action).
+		configtest >/dev/null 2>&1
+		RETVAL=$?
+		if [ $RETVAL != 0 ]; then
+			show "Checking %s configuration" "qemu-ga"; fail
+			nls 'Configuration test failed. See details with %s "checkconfig"' $0
+			exit $RETVAL
+		fi
+	fi
+}
+
+start() {
+	# Check if the service is already running?
+	if [ -f /var/lock/subsys/qemu-ga ]; then
+		msg_already_running "qemu-ga"
+		return
+	fi
+
+	checkconfig
+	msg_starting "qemu-ga"
+	daemon /usr/bin/qemu-ga -d -l /var/log/qemu-ga
+	RETVAL=$?
+	[ $RETVAL -eq 0 ] && touch /var/lock/subsys/qemu-ga
+}
+
+stop() {
+	if [ ! -f /var/lock/subsys/qemu-ga ]; then
+		msg_not_running "qemu-ga"
+		return
+	fi
+
+	# Stop daemons.
+	msg_stopping "qemu-ga"
+	killproc --pidfile $pidfile qemu-ga -TERM
+	rm -f /var/lock/subsys/qemu-ga
+}
+
+condrestart() {
+	if [ ! -f /var/lock/subsys/qemu-ga ]; then
+		msg_not_running "qemu-ga"
+		RETVAL=$1
+		return
+	fi
+
+	checkconfig
+	stop
+	start
+}
+
+RETVAL=0
+# See how we were called.
+case "$1" in
+  start)
+	start
+	;;
+  stop)
+	stop
+	;;
+  restart)
+	checkconfig
+	stop
+	start
+	;;
+  try-restart)
+	condrestart 0
+	;;
+  force-reload)
+	condrestart 7
+	;;
+  checkconfig|configtest)
+	checkconfig 1
+	;;
+  status)
+	status --pidfile $pidfile qemu-ga
+	RETVAL=$?
+	;;
+  *)
+	msg_usage "$0 {start|stop|restart|try-restart|force-reload|checkconfig|status}"
+	exit 3
+esac
+
+exit $RETVAL
diff --git a/qemu-guest-agent.logrotate b/qemu-guest-agent.logrotate
new file mode 100644
index 0000000..0c64059
--- /dev/null
+++ b/qemu-guest-agent.logrotate
@@ -0,0 +1,6 @@
+/var/log/qemu-ga
+{
+	postrotate
+		/sbin/service qemu-ga restart >/dev/null
+	endscript
+}
================================================================

---- gitweb:

http://git.pld-linux.org/gitweb.cgi/packages/qemu.git/commitdiff/ccb0f0ea96ede99bb7d577a06ac18c2d29981526



More information about the pld-cvs-commit mailing list