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 1 commit
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
25 changes: 5 additions & 20 deletions iocage_cli/destroy.py
Expand Up @@ -112,15 +112,6 @@ def cli(force, release, download, jails, recursive):

if jails and not release:
for jail in jails:

iocage = ioc.IOCage(jail=jail, skip_jails=True)
if iocage.jail.running:
ioc_common.logit({
"level" : "EXCEPTION",
"message": (f"Jail {jail} is still running, "
f"cannot destroy running jail")})
return

if not force:
ioc_common.logit({
"level": "WARNING",
Expand All @@ -132,18 +123,11 @@ def cli(force, release, download, jails, recursive):

child_test(zfs, iocroot, jail, "jail", force=force,
recursive=recursive)
iocage.destroy_jail()

ioc.IOCage(jail=jail,
skip_jails=True).destroy_jail(force=force)
elif jails and release:
for release in jails:

iocage = ioc.IOCage(jail=release, skip_jails=True)
if iocage.jail.running:
ioc_common.logit({
"level": "EXCEPTION",
"message": (f"Jail {release} is still running, "
f"cannot destroy running jail")})
return

if not force:
ioc_common.logit({
"level": "WARNING",
Expand All @@ -156,7 +140,8 @@ def cli(force, release, download, jails, recursive):
child_test(zfs, iocroot, release, "release", force=force,
recursive=recursive)

iocage.destroy_release(download)
ioc.IOCage(jail=release,
skip_jails=True).destroy_release(download)
elif not jails and release:
ioc_common.logit({
"level": "EXCEPTION",
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")
}
Corvan marked this conversation as resolved.
Show resolved Hide resolved
)
return
Corvan marked this conversation as resolved.
Show resolved Hide resolved
else:
ioc_common.logit(
{
"level": "INFO",
"message": f"Stopping {uuid}"
},
_callback=self.callback,
silent=self.silent)

ioc_common.logit(
{
Expand Down