verifying a given jail is running

From: Dan Langille <>
Date: Wed, 18 Aug 2021 12:21:28 -0400

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:

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 ( 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      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
   echo jail is not running

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

Thank you.

Dan Langille
Received on Wed Aug 18 2021 - 16:21:28 UTC

Original text of this message