xref: /openbmc/openbmc/poky/meta/recipes-devtools/qemu/qemu/qemu-guest-agent.init (revision fc113eade321128fc43b0b299e81ad07fc1edf3d)
1*fc113eadSAndrew Geissler# SPDX-License-Identifier: GPL-2.0-only
2*fc113eadSAndrew Geissler# Initially written by: Michael Tokarev <mjt@tls.msk.ru>
3*fc113eadSAndrew Geissler# For QEMU Debian downstream package
4*fc113eadSAndrew Geissler
5*fc113eadSAndrew Geisslerset -e
6*fc113eadSAndrew Geissler
7*fc113eadSAndrew Geissler. /etc/init.d/functions
8*fc113eadSAndrew Geissler
9*fc113eadSAndrew GeisslerPATH=/sbin:/usr/sbin:/bin:/usr/bin
10*fc113eadSAndrew GeisslerDESC="QEMU Guest Agent"
11*fc113eadSAndrew GeisslerNAME=qemu-ga
12*fc113eadSAndrew GeisslerDAEMON=@bindir@/$NAME
13*fc113eadSAndrew GeisslerPIDFILE=/var/run/$NAME.pid
14*fc113eadSAndrew Geissler
15*fc113eadSAndrew Geissler# config
16*fc113eadSAndrew GeisslerDAEMON_ARGS=""
17*fc113eadSAndrew Geissler# default transport
18*fc113eadSAndrew GeisslerTRANSPORT=virtio-serial:/dev/virtio-ports/org.qemu.guest_agent.0
19*fc113eadSAndrew GeisslerNO_START=0
20*fc113eadSAndrew Geissler
21*fc113eadSAndrew Geisslertest ! -r /etc/default/qemu-guest-agent || . /etc/default/qemu-guest-agent
22*fc113eadSAndrew Geisslertest "$NO_START" = "0" || exit 0
23*fc113eadSAndrew Geisslertest -x "$DAEMON" || exit 0
24*fc113eadSAndrew Geissler
25*fc113eadSAndrew Geissler#
26*fc113eadSAndrew Geissler# Function that checks whenever system has necessary environment
27*fc113eadSAndrew Geissler# It also splits $TRANSPORT into $method and $path
28*fc113eadSAndrew Geissler#
29*fc113eadSAndrew Geisslerdo_check_transport() {
30*fc113eadSAndrew Geissler	method=${TRANSPORT%%:*};
31*fc113eadSAndrew Geissler	path=${TRANSPORT#*:}
32*fc113eadSAndrew Geissler	case "$method" in
33*fc113eadSAndrew Geissler	    virtio-serial | isa-serial)
34*fc113eadSAndrew Geissler		if [ ! -e "$path" ]; then
35*fc113eadSAndrew Geissler		    echo "$NAME: transport endpoint not found, not starting"
36*fc113eadSAndrew Geissler		    return 1
37*fc113eadSAndrew Geissler		fi
38*fc113eadSAndrew Geissler		;;
39*fc113eadSAndrew Geissler	esac
40*fc113eadSAndrew Geissler}
41*fc113eadSAndrew Geissler
42*fc113eadSAndrew Geisslercase "$1" in
43*fc113eadSAndrew Geissler  start)
44*fc113eadSAndrew Geissler	do_check_transport || exit 0
45*fc113eadSAndrew Geissler	echo -n "Starting $DESC: "
46*fc113eadSAndrew Geissler	start-stop-daemon -S -p $PIDFILE -x "$DAEMON" -- \
47*fc113eadSAndrew Geissler		$DAEMON_ARGS -d -m "$method" -p "$path"
48*fc113eadSAndrew Geissler	echo "$NAME."
49*fc113eadSAndrew Geissler	;;
50*fc113eadSAndrew Geissler  stop)
51*fc113eadSAndrew Geissler	echo -n "Stopping $DESC: "
52*fc113eadSAndrew Geissler	start-stop-daemon -K -x "$DAEMON" -p $PIDFILE
53*fc113eadSAndrew Geissler	echo "$NAME."
54*fc113eadSAndrew Geissler	;;
55*fc113eadSAndrew Geissler  status)
56*fc113eadSAndrew Geissler	status "$DAEMON"
57*fc113eadSAndrew Geissler	exit $?
58*fc113eadSAndrew Geissler	;;
59*fc113eadSAndrew Geissler  restart|force-reload)
60*fc113eadSAndrew Geissler	do_check_transport || exit 0
61*fc113eadSAndrew Geissler	echo -n "Restarting $DESC: "
62*fc113eadSAndrew Geissler	start-stop-daemon -K -x "$DAEMON" -p $PIDFILE
63*fc113eadSAndrew Geissler	sleep 1
64*fc113eadSAndrew Geissler	start-stop-daemon -S -p $PIDFILE -x "$DAEMON" -- \
65*fc113eadSAndrew Geissler		$DAEMON_ARGS -d -m "$method" -p "$path"
66*fc113eadSAndrew Geissler	echo "$NAME."
67*fc113eadSAndrew Geissler	;;
68*fc113eadSAndrew Geissler  *)
69*fc113eadSAndrew Geissler	N=/etc/init.d/$NAME
70*fc113eadSAndrew Geissler	echo "Usage: $N {start|stop|status|restart|force-reload}" >&2
71*fc113eadSAndrew Geissler	exit 1
72*fc113eadSAndrew Geissler	;;
73*fc113eadSAndrew Geissleresac
74*fc113eadSAndrew Geissler
75*fc113eadSAndrew Geisslerexit 0
76