Commit 0bd35d79 authored by Ben Hutchings's avatar Ben Hutchings

hyperv-daemons: Add init scripts

Also add a helper executable that implements the check for Hyper-V
(like ConditionVirtualization=microsoft in the systemd units).

(cherry picked from commit 50747480c882dae7d3c8f7b4d0df5cf3276c4ee5)
parent 5f504574
PROGS = \
hv_fcopy_daemon \
hv_kvp_daemon \
hv_vss_daemon
hv_vss_daemon \
check-hyperv
OUTDIR = tools/hv
prefix = /usr/sbin
......@@ -9,7 +10,8 @@ prefix = /usr/sbin
include ../../Makefile.inc
install-local-progs: $(PROGS)
@for p in $^; do \
@for p in $(filter-out check-hyperv,$^); do \
echo " install -m755 '$$p' '$(DESTDIR)/$(prefix)'"; \
install -D -m755 "$$p" "$(DESTDIR)/$(prefix)/$$(basename $$p)"; \
done
install -D -m755 check-hyperv '$(DESTDIR)/lib/hyperv-daemons/check-hyperv'
/*
* This program is derived from systemd.
*
* Copyright 2011 Lennart Poettering
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdbool.h>
#include <stdint.h>
#include <string.h>
#define streq(a, b) (!strcmp(a, b))
#define ELEMENTSOF(a) (sizeof(a) / sizeof((a)[0]))
enum {
VIRTUALIZATION_NONE,
VIRTUALIZATION_VM_OTHER,
VIRTUALIZATION_MICROSOFT,
};
static int detect_vm_cpuid(void) {
static const struct {
const char *cpuid;
int id;
} cpuid_vendor_table[] = {
/* http://msdn.microsoft.com/en-us/library/ff542428.aspx */
{ "Microsoft Hv", VIRTUALIZATION_MICROSOFT },
};
uint32_t eax, ecx;
bool hypervisor;
/* http://lwn.net/Articles/301888/ */
#if defined (__i386__)
#define REG_a "eax"
#define REG_b "ebx"
#elif defined (__amd64__)
#define REG_a "rax"
#define REG_b "rbx"
#endif
/* First detect whether there is a hypervisor */
eax = 1;
__asm__ __volatile__ (
/* ebx/rbx is being used for PIC! */
" push %%"REG_b" \n\t"
" cpuid \n\t"
" pop %%"REG_b" \n\t"
: "=a" (eax), "=c" (ecx)
: "0" (eax)
);
hypervisor = !!(ecx & 0x80000000U);
if (hypervisor) {
union {
uint32_t sig32[3];
char text[13];
} sig = {};
unsigned j;
/* There is a hypervisor, see what it is */
eax = 0x40000000U;
__asm__ __volatile__ (
/* ebx/rbx is being used for PIC! */
" push %%"REG_b" \n\t"
" cpuid \n\t"
" mov %%ebx, %1 \n\t"
" pop %%"REG_b" \n\t"
: "=a" (eax), "=r" (sig.sig32[0]), "=c" (sig.sig32[1]), "=d" (sig.sig32[2])
: "0" (eax)
);
for (j = 0; j < ELEMENTSOF(cpuid_vendor_table); j ++)
if (streq(sig.text, cpuid_vendor_table[j].cpuid))
return cpuid_vendor_table[j].id;
return VIRTUALIZATION_VM_OTHER;
}
return VIRTUALIZATION_NONE;
}
int main(void)
{
return detect_vm_cpuid() != VIRTUALIZATION_MICROSOFT;
}
linux-tools (4.4-3) UNRELEASED; urgency=medium
* hyperv-daemons: Add init scripts
-- Ben Hutchings <ben@decadent.org.uk> Sun, 21 Feb 2016 15:03:44 +0000
linux-tools (4.4-2) unstable; urgency=medium
* linux-perf: Include version number in strace groups installation directory
......
......@@ -30,3 +30,22 @@ License: GPL-2
Files: debian/*
Copyright: 2006-2012 Debian kernel team
License: GPL-2
Files: debian/build/tools/hv/check-hyperv.c
Copyright: 2011 Lennart Poettering
License: LGPL-2.1
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
.
You should have received a copy of the GNU Lesser General Public License
along with this program; If not, see <http://www.gnu.org/licenses/>.
.
On Debian systems, the complete text of the GNU Lesser General Public
License version 2.1 can be found in `/usr/share/common-licenses/LGPL-2.1'.
#! /bin/sh
### BEGIN INIT INFO
# Provides: hyperv-daemons.hv-fcopy-daemon
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Hyper-V file copy service (FCOPY) daemon
### END INIT INFO
PATH=/sbin:/usr/sbin:/bin:/usr/bin
DESC="Hyper-V file copy service (FCOPY) daemon"
NAME=hv_fcopy_daemon
DAEMON=/usr/sbin/$NAME
PIDFILE=/var/run/$NAME.pid
SCRIPTNAME=/etc/init.d/hyperv-daemons.hv-fcopy-daemon
# Exit if the package is not installed
[ -x "$DAEMON" ] || exit 0
# Exit if we are not running under Hyper-V or the kernel device does not exist
/lib/hyperv-daemons/check-hyperv || exit 0
[ -e "/dev/vmbus/hv_fcopy" ] || exit 0
# Load the VERBOSE setting and other rcS variables
. /lib/init/vars.sh
# Define LSB log_* functions.
. /lib/lsb/init-functions
#
# Function that starts the daemon/service
#
do_start()
{
# Return
# 0 if daemon has been started
# 1 if daemon was already running
# 2 if daemon could not be started
start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \
|| return 1
start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --background --make-pidfile -- -n \
|| return 2
}
#
# Function that stops the daemon/service
#
do_stop()
{
# Return
# 0 if daemon has been stopped
# 1 if daemon was already stopped
# 2 if daemon could not be stopped
# other if a failure occurred
start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $NAME
[ "$?" = 2 ] && return 2
start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON
RETVAL=$?
[ "$RETVAL" = 2 ] && return 2
# Many daemons don't delete their pidfiles when they exit.
rm -f $PIDFILE
return "$RETVAL"
}
case "$1" in
start)
[ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
do_start
case "$?" in
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
esac
;;
stop)
[ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
do_stop
case "$?" in
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
esac
;;
status)
status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
;;
restart|force-reload)
log_daemon_msg "Restarting $DESC" "$NAME"
do_stop
case "$?" in
0|1)
do_start
case "$?" in
0) log_end_msg 0 ;;
1) log_end_msg 1 ;; # Old process is still running
*) log_end_msg 1 ;; # Failed to start
esac
;;
*)
# Failed to stop
log_end_msg 1
;;
esac
;;
*)
echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
exit 3
;;
esac
:
#! /bin/sh
### BEGIN INIT INFO
# Provides: hyperv-daemons.hv-kvp-daemon
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Hyper-V key-value pair (KVP) daemon
### END INIT INFO
PATH=/sbin:/usr/sbin:/bin:/usr/bin
DESC="Hyper-V key-value pair (KVP) daemon"
NAME=hv_kvp_daemon
DAEMON=/usr/sbin/$NAME
PIDFILE=/var/run/$NAME.pid
SCRIPTNAME=/etc/init.d/hyperv-daemons.hv-kvp-daemon
# Exit if the package is not installed
[ -x "$DAEMON" ] || exit 0
# Exit if we are not running under Hyper-V
/lib/hyperv-daemons/check-hyperv || exit 0
# Load the VERBOSE setting and other rcS variables
. /lib/init/vars.sh
# Define LSB log_* functions.
. /lib/lsb/init-functions
#
# Function that starts the daemon/service
#
do_start()
{
# Return
# 0 if daemon has been started
# 1 if daemon was already running
# 2 if daemon could not be started
start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \
|| return 1
start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --background --make-pidfile -- -n \
|| return 2
}
#
# Function that stops the daemon/service
#
do_stop()
{
# Return
# 0 if daemon has been stopped
# 1 if daemon was already stopped
# 2 if daemon could not be stopped
# other if a failure occurred
start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $NAME
[ "$?" = 2 ] && return 2
start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON
RETVAL=$?
[ "$RETVAL" = 2 ] && return 2
# Many daemons don't delete their pidfiles when they exit.
rm -f $PIDFILE
return "$RETVAL"
}
case "$1" in
start)
[ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
do_start
case "$?" in
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
esac
;;
stop)
[ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
do_stop
case "$?" in
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
esac
;;
status)
status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
;;
restart|force-reload)
log_daemon_msg "Restarting $DESC" "$NAME"
do_stop
case "$?" in
0|1)
do_start
case "$?" in
0) log_end_msg 0 ;;
1) log_end_msg 1 ;; # Old process is still running
*) log_end_msg 1 ;; # Failed to start
esac
;;
*)
# Failed to stop
log_end_msg 1
;;
esac
;;
*)
echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
exit 3
;;
esac
:
#! /bin/sh
### BEGIN INIT INFO
# Provides: hyperv-daemons.hv-vss-daemon
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Hyper-V volume shadow copy service (VSS) daemon
### END INIT INFO
PATH=/sbin:/usr/sbin:/bin:/usr/bin
DESC="Hyper-V volume shadow copy service (VSS) daemon"
NAME=hv_vss_daemon
DAEMON=/usr/sbin/$NAME
PIDFILE=/var/run/$NAME.pid
SCRIPTNAME=/etc/init.d/hyperv-daemons.hv-vss-daemon
# Exit if the package is not installed
[ -x "$DAEMON" ] || exit 0
# Exit if we are not running under Hyper-V
/lib/hyperv-daemons/check-hyperv || exit 0
# Load the VERBOSE setting and other rcS variables
. /lib/init/vars.sh
# Define LSB log_* functions.
. /lib/lsb/init-functions
#
# Function that starts the daemon/service
#
do_start()
{
# Return
# 0 if daemon has been started
# 1 if daemon was already running
# 2 if daemon could not be started
start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \
|| return 1
start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --background --make-pidfile -- -n \
|| return 2
}
#
# Function that stops the daemon/service
#
do_stop()
{
# Return
# 0 if daemon has been stopped
# 1 if daemon was already stopped
# 2 if daemon could not be stopped
# other if a failure occurred
start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $NAME
[ "$?" = 2 ] && return 2
start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON
RETVAL=$?
[ "$RETVAL" = 2 ] && return 2
# Many daemons don't delete their pidfiles when they exit.
rm -f $PIDFILE
return "$RETVAL"
}
case "$1" in
start)
[ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
do_start
case "$?" in
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
esac
;;
stop)
[ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
do_stop
case "$?" in
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
esac
;;
status)
status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
;;
restart|force-reload)
log_daemon_msg "Restarting $DESC" "$NAME"
do_stop
case "$?" in
0|1)
do_start
case "$?" in
0) log_end_msg 0 ;;
1) log_end_msg 1 ;; # Old process is still running
*) log_end_msg 1 ;; # Failed to start
esac
;;
*)
# Failed to stop
log_end_msg 1
;;
esac
;;
*)
echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
exit 3
;;
esac
:
......@@ -95,9 +95,19 @@ install-hyperv-daemons: $(STAMPS_DIR)/build
dh_prep
$(MAKE) -C $(BUILD_DIR)/tools/hv install top_srcdir=$(CURDIR) DESTDIR=$(DIR)
dh_install
for service in fcopy kvp vss; do \
install -D -m755 debian/hyperv-daemons.hv-$$service-daemon.init \
$(DIR)/etc/init.d/hyperv-daemons.hv-$$service-daemon \
|| break; \
done
dh_installchangelogs
dh_installdocs
dh_systemd_enable
for service in fcopy kvp vss; do \
dh_installinit --name hyperv-daemons.hv-$$service-daemon \
--onlyscripts \
|| break; \
done
dh_systemd_start
dh_lintian
dh_strip
......
......@@ -55,7 +55,7 @@ Description: USB device sharing system over IP network
Package: hyperv-daemons
Architecture: i386 amd64 x32
Depends: ${shlibs:Depends}, ${misc:Depends}
Depends: lsb-base (>= 3.2-14), ${shlibs:Depends}, ${misc:Depends}
Section: admin
Description: Support daemons for Linux running on Hyper-V
Suite of daemons for Linux guests running on Hyper-V, consisting of
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment