Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 18 Aug 2021 12:21:28 -0400
From:      Dan Langille <dan@langille.org>
To:        freebsd-hackers@freebsd.org
Subject:   verifying a given jail is running
Message-ID:  <329b32d4-8f8b-d672-21b1-80820d5b318f@langille.org>

next in thread | raw e-mail | index | archive | help
Hello,

I want a script to verify a given jail is running. I think I have a 
rather simple solution but I'm presenting what I tried as I went along.

I have a Nagios script for monitoring that a given jail is running:

https://git.langille.org/dvl/nagios/src/branch/master/check_freebsd_jails

I found that via a search, made some improvements, and I'm now using it 
in production.

It seems to be low-overhead:

$ time /usr/local/libexec/nagios-custom/check_freebsd_jails freshports
Jail freshports (10.55.0.37) is running under JID 156 in /jails/freshports

real    0m0.025s
user    0m0.011s
sys    0m0.017s

I could easily invoke that from within my scripts.

I then thought: why not jexec?

$ time sudo jexec freshports date
Wed Aug 18 15:23:25 UTC 2021

real    0m0.029s
user    0m0.013s
sys    0m0.003s

Roughly the same time.

Next to try was:

$ time jls -j freshports
    JID  IP Address      Hostname                      Path
    156  10.55.0.37      freshports                    /jails/freshports

real    0m0.003s
user    0m0.000s
sys    0m0.005s

That's much faster, not that speed is really relevant here.

I could use it like this in a shell script.

jls -j freshports > /dev/null 2>&1
if [ $? = 0 ] ; then
   echo jail is running
else
   echo jail is not running
fi

The main reason I need this: Verifying the jail is running before 
continuing with a script.

Thank you.

-- 
Dan Langille
dan@langille.org



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?329b32d4-8f8b-d672-21b1-80820d5b318f>