[virt-who] Export variables from config file in initscript
by Radek Novacek
commit 885daa6dd46fdf7457175f8a07da13bf3619a131
Author: Radek Novacek <rnovacek(a)redhat.com>
Date: Mon Sep 5 09:27:53 2011 +0200
Export variables from config file in initscript
virt-who-initscript | 3 +++
1 files changed, 3 insertions(+), 0 deletions(-)
---
diff --git a/virt-who-initscript b/virt-who-initscript
index 88f13bb..7688eb3 100644
--- a/virt-who-initscript
+++ b/virt-who-initscript
@@ -26,6 +26,9 @@ config="/etc/sysconfig/virt-who"
[ -e /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog
+export VIRTWHO_BACKGROUND
+export VIRTWHO_DEBUG
+
lockfile=/var/lock/subsys/$prog
start() {
12 years, 9 months
[virt-who] Create directories before installation in Makefile, increase version number to 0.3 in Makefile
by Radek Novacek
commit a7a83e161d73192b0acd25aaca828d1c51f378d3
Author: Radek Novacek <rnovacek(a)redhat.com>
Date: Mon Sep 5 09:17:31 2011 +0200
Create directories before installation in Makefile, increase version number to 0.3 in Makefile
Makefile | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)
---
diff --git a/Makefile b/Makefile
index 0a5bc50..46c13c3 100644
--- a/Makefile
+++ b/Makefile
@@ -1,6 +1,6 @@
name = virt-who
-version = 0.2
+version = 0.3
.PHONY: pack check install srpm rpm rpmlint upload
@@ -13,7 +13,7 @@ check:
pyflakes *.py
install:
- install -d $(DESTDIR)/usr/share/$(name)/ $(DESTDIR)/usr/bin
+ install -d $(DESTDIR)/usr/share/$(name)/ $(DESTDIR)/usr/bin $(DESTDIR)/etc/rc.d/init.d $(DESTDIR)/etc/sysconfig
install -pm 0644 *.py $(DESTDIR)/usr/share/$(name)/
install virt-who $(DESTDIR)/usr/bin/
install virt-who-initscript $(DESTDIR)/etc/rc.d/init.d/virt-who
12 years, 9 months
[virt-who] Add initscript and configuration file
by Radek Novacek
commit 56775a95bd48d41707c86f8a45293630bf3df174
Author: Radek Novacek <rnovacek(a)redhat.com>
Date: Thu Sep 1 08:25:05 2011 +0200
Add initscript and configuration file
Makefile | 2 +
virt-who-initscript | 106 +++++++++++++++++++++++++++++++++++++++++++++++++++
virt-who.conf | 2 +
virt-who.py | 8 ++++
virt-who.spec | 26 ++++++++++++-
5 files changed, 143 insertions(+), 1 deletions(-)
---
diff --git a/Makefile b/Makefile
index 83ba8e1..0a5bc50 100644
--- a/Makefile
+++ b/Makefile
@@ -16,6 +16,8 @@ install:
install -d $(DESTDIR)/usr/share/$(name)/ $(DESTDIR)/usr/bin
install -pm 0644 *.py $(DESTDIR)/usr/share/$(name)/
install virt-who $(DESTDIR)/usr/bin/
+ install virt-who-initscript $(DESTDIR)/etc/rc.d/init.d/virt-who
+ install virt-who.conf $(DESTDIR)/etc/sysconfig/virt-who
srpm: pack
rpmbuild --define "_sourcedir $(PWD)" --define "_specdir $(PWD)" --define "_srcrpmdir $(PWD)" -bs $(name).spec
diff --git a/virt-who-initscript b/virt-who-initscript
new file mode 100644
index 0000000..88f13bb
--- /dev/null
+++ b/virt-who-initscript
@@ -0,0 +1,106 @@
+#!/bin/sh
+#
+# virt-who Agent for reporting virtual guest IDs to subscription-manager
+#
+# chkconfig: 2345 95 95
+# description: Agent for reporting virtual guest IDs to subscription-manager
+
+### BEGIN INIT INFO
+# Provides: virt-who
+# Required-Start: $network libvirtd
+# Required-Stop:
+# Should-Start:
+# Should-Stop:
+# Default-Start: 2 3 4 5
+# Default-Stop: 0 1 6
+# Short-Description: start and stop virt-who
+# Description: Agent for reporting virtual guest IDs to subscription-manager
+### END INIT INFO
+
+# Source function library.
+. /etc/rc.d/init.d/functions
+
+exec="/usr/bin/virt-who"
+prog="virt-who"
+config="/etc/sysconfig/virt-who"
+
+[ -e /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog
+
+lockfile=/var/lock/subsys/$prog
+
+start() {
+ [ -x $exec ] || exit 5
+ [ -f $config ] || exit 6
+ echo -n $"Starting $prog: "
+ # if not running, start it up here, usually something like "daemon $exec"
+ daemon $exec
+ retval=$?
+ echo
+ [ $retval -eq 0 ] && touch $lockfile
+ return $retval
+}
+
+stop() {
+ echo -n $"Stopping $prog: "
+ # stop it here, often "killproc $prog"
+ killproc $prog
+ retval=$?
+ echo
+ [ $retval -eq 0 ] && rm -f $lockfile
+ return $retval
+}
+
+restart() {
+ stop
+ start
+}
+
+reload() {
+ restart
+}
+
+force_reload() {
+ restart
+}
+
+rh_status() {
+ # run checks to determine if the service is running or use generic status
+ status $prog
+}
+
+rh_status_q() {
+ rh_status >/dev/null 2>&1
+}
+
+
+case "$1" in
+ start)
+ rh_status_q && exit 0
+ $1
+ ;;
+ stop)
+ rh_status_q || exit 0
+ $1
+ ;;
+ restart)
+ $1
+ ;;
+ reload)
+ rh_status_q || exit 7
+ $1
+ ;;
+ force-reload)
+ force_reload
+ ;;
+ status)
+ rh_status
+ ;;
+ condrestart|try-restart)
+ rh_status_q || exit 0
+ restart
+ ;;
+ *)
+ echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload}"
+ exit 2
+esac
+exit $?
\ No newline at end of file
diff --git a/virt-who.conf b/virt-who.conf
new file mode 100644
index 0000000..8916919
--- /dev/null
+++ b/virt-who.conf
@@ -0,0 +1,2 @@
+VIRTWHO_BACKGROUND=1
+VIRTWHO_DEBUG=0
\ No newline at end of file
diff --git a/virt-who.py b/virt-who.py
index 8c52701..e10f6c0 100644
--- a/virt-who.py
+++ b/virt-who.py
@@ -45,6 +45,14 @@ if __name__ == '__main__':
(options, args) = parser.parse_args()
+ # Handle enviromental variables
+ env = os.getenv("VIRTWHO_BACKGROUND", "0").strip().lower()
+ if env in ["1", "true"]:
+ options.background = True
+ env = os.getenv("VIRTWHO_DEBUG", "0").strip().lower()
+ if env in ["1", "true"]:
+ options.debug = True
+
if options.debug:
# Enable debugging output to be writen in /var/log
logger.setLevel(logging.DEBUG)
diff --git a/virt-who.spec b/virt-who.spec
index 548593e..65c16b8 100644
--- a/virt-who.spec
+++ b/virt-who.spec
@@ -1,5 +1,5 @@
Name: virt-who
-Version: 0.2
+Version: 0.3
Release: 1%{?dist}
Summary: Agent for reporting virtual guest IDs to subscription-manager
@@ -14,6 +14,10 @@ BuildRequires: python2-devel
Requires: libvirt-python
Requires: libvirt
Requires: python-rhsm
+Requires(post): chkconfig
+Requires(preun): chkconfig
+# This is for /sbin/service
+Requires(preun): initscripts
%description
Agent that collects information about virtual guests present in the system and
@@ -37,14 +41,34 @@ make DESTDIR=$RPM_BUILD_ROOT install
%clean
rm -rf $RPM_BUILD_ROOT
+%post
+# This adds the proper /etc/rc*.d links for the script
+/sbin/chkconfig --add virt-who
+
+%preun
+if [ $1 -eq 0 ] ; then
+ /sbin/service virt-who stop >/dev/null 2>&1
+ /sbin/chkconfig --del virt-who
+fi
+
+%postun
+if [ "$1" -ge "1" ] ; then
+ /sbin/service virt-who condrestart >/dev/null 2>&1 || :
+fi
+
%files
%doc README LICENSE
%{_bindir}/virt-who
%{_datadir}/virt-who/
+%{_sysconfdir}/rc.d/init.d/virt-who
+%config(noreplace) %{_sysconfdir}/sysconfig/virt-who
%changelog
+* Thu Sep 01 2011 Radek Novacek <rnovacek(a)redhat.com> - 0.3-1
+- Add initscript and configuration file
+
* Mon Aug 22 2011 Radek Novacek <rnovacek(a)redhat.com> - 0.2-1
- Update to upstream version 0.2
- Add Requires: libvirt
12 years, 9 months