From ea0102f644d1f646e7f099df95e63a488916274e Mon Sep 17 00:00:00 2001 From: David Scott Date: Thu, 31 May 2012 11:08:43 +0100 Subject: [PATCH] fs: add an init.d script, set RPM BuildArch: noarch --- Makefile | 2 + python/fs.py | 8 +++- python/init.d-xcp-sm-fs | 92 ++++++++++++++++++++++++++++++++++++++++ python/xcp-sm-fs.conf | 2 + python/xcp-sm-fs.spec.in | 1 + 5 files changed, 104 insertions(+), 1 deletion(-) create mode 100755 python/init.d-xcp-sm-fs diff --git a/Makefile b/Makefile index 76116d3a..d2c4bbaa 100644 --- a/Makefile +++ b/Makefile @@ -43,6 +43,8 @@ install: idl ${INSTALL} python/xcp-sm-fs ${DESTDIR}/usr/bin/xcp-sm-fs ${MKDIR} -p ${DESTDIR}/etc ${INSTALL} python/xcp-sm-fs.conf ${DESTDIR}/etc/xcp-sm-fs.conf + ${MKDIR} -p ${DESTDIR}/etc/rc.d/init.d + ${INSTALL} python/init.d-xcp-sm-fs ${DESTDIR}/etc/rc.d/init.d/xcp-sm-fs .PHONY: python/xcp-sm-fs.spec python/xcp-sm-fs.spec: python/xcp-sm-fs.spec.in diff --git a/python/fs.py b/python/fs.py index 1a1435c4..6a765859 100755 --- a/python/fs.py +++ b/python/fs.py @@ -499,7 +499,8 @@ def detach(self, dbg, dp, sr, vdi): "ip": None, "socket": "/var/xapi/sm/fs", "daemon": False, - "config": "/etc/xcp-sm-fs.conf" + "config": "/etc/xcp-sm-fs.conf", + "pidfile": "/var/run/xcp-sm-fs.pid" } parser = OptionParser() @@ -549,6 +550,11 @@ def detach(self, dbg, dp, sr, vdi): if settings["daemon"]: log("daemonising") xcp.daemonize() + pidfile = open(settings["pidfile"], "w") + try: + pidfile.write(str(os.getpid())) + finally: + pidfile.close() server = None if tcp: diff --git a/python/init.d-xcp-sm-fs b/python/init.d-xcp-sm-fs new file mode 100755 index 00000000..c9881ec3 --- /dev/null +++ b/python/init.d-xcp-sm-fs @@ -0,0 +1,92 @@ +#! /bin/bash +# +# xcp-sm-fs Start/Stop the XCP filesystem storage backend +# +# chkconfig: 2345 23 77 +# description: Storage backend which stores disks in local or remote files +# processname: xcp-sm-fs +# config: /etc/xcp-sm-fs.conf +# pidfile: /var/run/xcp-sm-fs.pid + +# Source function library. +. /etc/init.d/functions + +if [ -f /etc/sysconfig/xcp-sm-fs ]; then + . /etc/sysconfig/xcp-sm-fs +fi + +start() { + echo -n $"Starting xcp-sm-fs: " + + /usr/bin/xcp-sm-fs + RETVAL=$? + + if [ $RETVAL -eq 0 ]; then + touch /var/lock/subsys/xcp-sm-fs + echo -n $"OK" + success $"OK" + echo + return 0 + else + echo -n $"failed to start xcp-sm-fs." + failure $"failed to start xcp-sm-fs." + killproc xcp-sm-fs + rm -f /var/lock/subsys/xcp-sm-fs /var/run/xcp-sm-fs.pid + echo + return 1 + fi +} + +stop() { + echo -n $"Stopping xcp-sm-fs: " + if [ ! -e /var/lock/subsys/xcp-sm-fs ]; then + echo -n $"cannot stop xcp-sm-fs: xcp-sm-fs is not running." + failure $"cannot stop xcp-sm-fs: xcp-sm-fs is not running." + echo + return 1; + fi + killproc xcp-sm-fs + RETVAL=$? + if [ $RETVAL -eq 0 ]; then + logger "xcp-sm-fs stopped forcibly" + success $"xcp-sm-fs stopped successfully" + echo + rm -f /var/run/xcp-sm-fs.pid /var/lock/subsys/xcp-sm-fs + else + logger "failed to stop xcp-sm-fs" + failure $"failed to stop xcp-sm-fs" + echo + fi + + return $RETVAL +} + +rhstatus() { + status xcp-sm-fs +} + +restart() { + stop + start +} + +case "$1" in + start) + start + ;; + stop) + stop + ;; + restart) + restart + ;; + status) + rhstatus + ;; + condrestart) + [ -f /var/lock/subsys/xcp-sm-fs ] && restart || : + ;; + *) + echo $"Usage: $0 {start|stop|status|restart|condrestart}" + exit 1 +esac diff --git a/python/xcp-sm-fs.conf b/python/xcp-sm-fs.conf index 833420f5..5390221a 100644 --- a/python/xcp-sm-fs.conf +++ b/python/xcp-sm-fs.conf @@ -10,3 +10,5 @@ log = stdout: socket = /var/xapi/sm/fs daemon = True + +# pidfile = /var/run/xcp-sm-fs.pid \ No newline at end of file diff --git a/python/xcp-sm-fs.spec.in b/python/xcp-sm-fs.spec.in index a5317ff4..f567a616 100644 --- a/python/xcp-sm-fs.spec.in +++ b/python/xcp-sm-fs.spec.in @@ -10,6 +10,7 @@ URL: http://www.xen.org Source0: xcp-sm-fs-%{version}.tar.bz2 BuildRoot: %{_tmppath}/%{name}-%{version}-root BuildRequires: ocaml omake ocaml-findlib ocaml-xmlm ocaml-type-conv ocaml-xmlm-devel +BuildArch: noarch %description Manages VM Virtual Disk Images (VDIs) for XCP, where each VDI corresponds to a set of