public inbox for isar-users@googlegroups.com
 help / color / mirror / Atom feed
From: Anton Mikanovich <amikan@ilbers.de>
To: isar-users@googlegroups.com
Cc: adriaan.schmidt@siemens.com, Anton Mikanovich <amikan@ilbers.de>
Subject: [PATCH 5/6] events: Cleanup lost schroot sessions if any
Date: Sat, 14 May 2022 10:07:35 +0300	[thread overview]
Message-ID: <20220514070736.12997-6-amikan@ilbers.de> (raw)
In-Reply-To: <20220514070736.12997-1-amikan@ilbers.de>

In case the user will only open imager schroot session but not close it
we need to find and clean it up.

Signed-off-by: Anton Mikanovich <amikan@ilbers.de>
---
 meta/classes/isar-events.bbclass | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/meta/classes/isar-events.bbclass b/meta/classes/isar-events.bbclass
index 92aff20..f1e9dcb 100644
--- a/meta/classes/isar-events.bbclass
+++ b/meta/classes/isar-events.bbclass
@@ -4,6 +4,8 @@
 # Copyright (C) 2015-2017 ilbers GmbH
 # Copyright (c) Siemens AG, 2018
 
+inherit sbuild
+
 addhandler build_started
 
 python build_started() {
@@ -51,6 +53,22 @@ python build_completed() {
 
     basepath = tmpdir + '/work/'
 
+    bitbake_id = d.getVar('BITBAKE_BUILD_ID', True)
+    sessions = subprocess.run('schroot -l --all-sessions | grep isar | grep %s' % bitbake_id,
+                              shell=True, stdout=subprocess.PIPE).stdout.decode('utf-8')
+    for line in sessions.splitlines():
+        session_id = line.split(':', 1)[1]
+        bb.debug(1, 'Closing imager session %s' % session_id)
+        id = subprocess.run("schroot -d / -r -c %s -- printenv -0 SCHROOT_ALIAS_NAME" % session_id,
+                            shell=True, check=True, stdout=subprocess.PIPE).stdout.decode('utf-8')
+        if id:
+            subprocess.run('schroot --recover-session -c %s' % session_id, shell=True, check=True)
+            subprocess.run('schroot -e -c %s' % session_id, shell=True, check=True)
+        if 'id' in locals():
+            d.setVar('SBUILD_CHROOT', id)
+            bb.build.exec_func('remove_mounts', d)
+            bb.build.exec_func('schroot_delete_configs', d)
+
     with open('/proc/mounts') as f:
         for line in f.readlines():
             if basepath in line:
-- 
2.17.1


  parent reply	other threads:[~2022-05-14  7:07 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-14  7:07 [PATCH 0/6] Imager schroot migration Anton Mikanovich
2022-05-14  7:07 ` [PATCH 1/6] sbuild: Allow setting custom config paths Anton Mikanovich
2022-05-14  7:07 ` [PATCH 2/6] base: Implement bitbake build ID Anton Mikanovich
2022-05-14  7:07 ` [PATCH 3/6] imager: Migrate from buildchroot to schroot Anton Mikanovich
2022-05-14  7:07 ` [PATCH 4/6] imager: Move image types " Anton Mikanovich
2022-05-14  7:07 ` Anton Mikanovich [this message]
2022-05-14  7:07 ` [PATCH 6/6] meta: Remove buildchroot Anton Mikanovich

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220514070736.12997-6-amikan@ilbers.de \
    --to=amikan@ilbers.de \
    --cc=adriaan.schmidt@siemens.com \
    --cc=isar-users@googlegroups.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox