#!/usr/bin/env cbsd
#v12.0.0
CIXARG="jname"
CIXOPTARG=""
MYDESC="xen process existence check"
CBSDMODULE="xen"
ADDHELP="
${H3_COLOR}Description${N0_COLOR}:

 Check whether a xen domain process for the specified virtual machine is running.
 Exits with 1 if the process exists (and outputs the PID to stdout),
 or 0 if no matching process is found.

 Used internally by xmigrate and other tools to verify VM state before
 performing operations such as live migration.

${H3_COLOR}Options${N0_COLOR}:

 ${N2_COLOR}jname=${N0_COLOR}     - target virtual machine name.

${H3_COLOR}Examples${N0_COLOR}:

 # cbsd xen-exist jname=myvm
 # cbsd xen-exist jname=myvm && echo \"VM is running\"

${H3_COLOR}See also${N0_COLOR}:

  cbsd xmigrate --help
  cbsd xstart --help
  cbsd xget --help

"

. ${subrdir}/nc.subr
cixinit
. ${subrdir}/xen.subr

check_for_xen_process -j ${jname}
_ret=$?

if [ -n "${vm_pid}" ]; then
	echo "${vm_pid}"
fi

exit ${_ret}
