From nobody Wed Aug 18 16:21:28 2021 X-Original-To: freebsd-hackers@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 2224E174F56C for ; Wed, 18 Aug 2021 16:21:48 +0000 (UTC) (envelope-from dan@langille.org) Received: from new1-smtp.messagingengine.com (new1-smtp.messagingengine.com [66.111.4.221]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 4GqY7b1JhXz4gqQ for ; Wed, 18 Aug 2021 16:21:47 +0000 (UTC) (envelope-from dan@langille.org) Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailnew.nyi.internal (Postfix) with ESMTP id 79075580B30 for ; Wed, 18 Aug 2021 12:21:36 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute3.internal (MEProxy); Wed, 18 Aug 2021 12:21:36 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=langille.org; h= to:from:subject:message-id:date:mime-version:content-type :content-transfer-encoding; s=fm2; bh=/Gt2Zzx8K6YTzc8UwoQlUaM2Jf ApC54CTk+tvP95UNo=; b=uDlRCrtemtsgfoX7s/XLP50xjv6LX12ZAkyQ8jqJeP TArOxp7kDM0hST01AFgTKak4zC4idb0+1xH22tiSauasJq7xiiCz5GFEUuzY5/wF jxDkdUrX+TU5ZqT4twzs9XkIsSe9LTTKS+e+Uxm3Okw089VhinunO3rKWsE/Pz3f ttZaTixwGo6KJfKSnen3aoaZRWgsze7S9Vmzlg4rEbOW+2W7PQHyzVuMz7JN0kZ4 CrIbkN8VpKy/9u5Vx18e75kYap4NglaZHmptCwqa+8by/CxOqcThvAXBhYxdWZGi eeoScTymV0cAuGgOZhTKOOUMGxt5wfhD2K5TQBcjYO9A== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:message-id:mime-version:subject:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm3; bh=/Gt2Zz x8K6YTzc8UwoQlUaM2JfApC54CTk+tvP95UNo=; b=MAgYjxV4M0SZIYXaEiiP14 uCp0qzl/uOkGTpHTD0QDncUag5Tni2VisQNntd9MWAd9GdWP43PWF2aPPlhKJql2 P/7J3MTpqJmNliGsPXnsEjxG/P0i0CV8KhMbuhxgN+gsQpfy3SbeVnzsKle0mpj6 gitQpBxvsLuVWSKD/a1W+iYXx1XkA9Q6OQawNP7ZzZQMJv0rtiIXkdUXHQveSqB4 ZxzgbGlplMiY75XrJlreF/GsrZxs9FUhm+GVeBiRI9Sk+LTZj4v7zYIV3ylFvWgh aeAzp5wA1EEvU3Vu2qxRpI4Z9oAqhoyaLH7D2TIDOMxKFqhIf+O7RRgDhkdfDHAg == X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvtddrleehgdelkecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhepvffhuffkffgfgggtgfesthekredttd efjeenucfhrhhomhepffgrnhcunfgrnhhgihhllhgvuceouggrnheslhgrnhhgihhllhgv rdhorhhgqeenucggtffrrghtthgvrhhnpeefveffhfduveevudfhjeetgfeukeeuvedvle ekhefgfeffueefueeltefhheevjeenucffohhmrghinheplhgrnhhgihhllhgvrdhorhhg necuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepuggrnh eslhgrnhhgihhllhgvrdhorhhg X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Wed, 18 Aug 2021 12:21:30 -0400 (EDT) To: freebsd-hackers@freebsd.org From: Dan Langille Subject: verifying a given jail is running Message-ID: <329b32d4-8f8b-d672-21b1-80820d5b318f@langille.org> Date: Wed, 18 Aug 2021 12:21:28 -0400 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.16; rv:52.0) Gecko/20100101 PostboxApp/7.0.48 List-Id: Technical discussions relating to FreeBSD List-Archive: https://lists.freebsd.org/archives/freebsd-hackers List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-hackers@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US X-Rspamd-Queue-Id: 4GqY7b1JhXz4gqQ X-Spamd-Bar: ----- Authentication-Results: mx1.freebsd.org; dkim=pass header.d=langille.org header.s=fm2 header.b=uDlRCrte; dkim=pass header.d=messagingengine.com header.s=fm3 header.b=MAgYjxV4; dmarc=pass (policy=none) header.from=langille.org; spf=pass (mx1.freebsd.org: domain of dan@langille.org designates 66.111.4.221 as permitted sender) smtp.mailfrom=dan@langille.org X-Spamd-Result: default: False [-5.10 / 15.00]; RCVD_VIA_SMTP_AUTH(0.00)[]; ARC_NA(0.00)[]; R_DKIM_ALLOW(-0.20)[langille.org:s=fm2,messagingengine.com:s=fm3]; FREEFALL_USER(0.00)[dan]; FROM_HAS_DN(0.00)[]; RWL_MAILSPIKE_GOOD(0.00)[66.111.4.221:from]; TO_MATCH_ENVRCPT_ALL(0.00)[]; R_SPF_ALLOW(-0.20)[+ip4:66.111.4.221]; MIME_GOOD(-0.10)[text/plain]; TO_DN_NONE(0.00)[]; PREVIOUSLY_DELIVERED(0.00)[freebsd-hackers@freebsd.org]; RCPT_COUNT_ONE(0.00)[1]; DWL_DNSWL_LOW(-1.00)[messagingengine.com:dkim]; RCVD_COUNT_THREE(0.00)[4]; NEURAL_HAM_MEDIUM(-1.00)[-1.000]; DKIM_TRACE(0.00)[langille.org:+,messagingengine.com:+]; DMARC_POLICY_ALLOW(-0.50)[langille.org,none]; NEURAL_HAM_SHORT(-1.00)[-1.000]; NEURAL_HAM_LONG(-1.00)[-1.000]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_TLS_LAST(0.00)[]; ASN(0.00)[asn:11403, ipnet:66.111.0.0/20, country:US]; MID_RHS_MATCH_FROM(0.00)[]; RCVD_IN_DNSWL_LOW(-0.10)[66.111.4.221:from] X-ThisMailContainsUnwantedMimeParts: N 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