Skip to content
This repository has been archived by the owner on Apr 4, 2024. It is now read-only.

Check if jail is running before destroying it and if, don't attempt t… #831

Merged
merged 6 commits into from Feb 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 8 additions & 4 deletions iocage_cli/destroy.py
Expand Up @@ -84,7 +84,7 @@ def child_test(zfs, iocroot, name, _type, force=False, recursive=False):
})
exit(1)
else:
return
return _children


@click.command(name="destroy", help="Destroy specified jail(s).")
Expand Down Expand Up @@ -125,7 +125,7 @@ def cli(force, release, download, jails, recursive):
recursive=recursive)

ioc.IOCage(jail=jail,
skip_jails=True).destroy_jail()
skip_jails=True).destroy_jail(force=force)
elif jails and release:
for release in jails:
if not force:
Expand All @@ -137,8 +137,12 @@ def cli(force, release, download, jails, recursive):
if not click.confirm("\nAre you sure?"):
continue

child_test(zfs, iocroot, release, "release", force=force,
recursive=recursive)
children = child_test(zfs, iocroot, release, "release",
force=force, recursive=recursive)

if children:
for child in children:
ioc.IOCage(jail=child).destroy_jail(force)

ioc.IOCage(jail=release,
skip_jails=True).destroy_release(download)
Expand Down
27 changes: 19 additions & 8 deletions iocage_lib/iocage.py
Expand Up @@ -686,7 +686,7 @@ def destroy_release(self, download=False):
ioc_destroy.IOCDestroy().__destroy_parse_datasets__(path,
stop=False)

def destroy_jail(self):
def destroy_jail(self, force):
"""
Destroys the supplied jail, to reduce perfomance hit,
call IOCage with skip_jails=True
Expand Down Expand Up @@ -743,13 +743,24 @@ def destroy_jail(self):
status, _ = self.list("jid", uuid=uuid)

if status:
ioc_common.logit(
{
"level": "INFO",
"message": f"Stopping {uuid}"
},
_callback=self.callback,
silent=self.silent)
if not force:
ioc_common.logit(
{
"level": "EXCEPTION",
"message": (f"Jail {uuid} is still running, "
f"please stop the jail first "
f"or destroy it with -f")
},
_callback=self.callback,
silent=self.silent)
else:
ioc_common.logit(
{
"level": "INFO",
"message": f"Stopping {uuid}"
},
_callback=self.callback,
silent=self.silent)

ioc_common.logit(
{
Expand Down