Navigation Menu

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

Conversation

Corvan
Copy link
Contributor

@Corvan Corvan commented Jan 28, 2019

I stumbled over the issue, that I tried to destroy a running Jail and did not realize that the error is due to it still running, so this Pull Request is a suggestion to deal with that.

@Corvan Corvan force-pushed the master branch 4 times, most recently from 565acf2 to d4e92b5 Compare January 28, 2019 09:18
@skarekrow
Copy link
Member

Hi thanks for the PR!

I have a few issues with it, but before I review it properly, what issue did you stumble over? iocage should have stopped the jail and then removed it.

root@freenas[~]# /root/iocage/iocage start foobar
* Starting foobar
  + Started OK
  + Using devfs_ruleset: 5
  + Starting services OK
  + Executing poststart OK
root@freenas[~]# /root/iocage/iocage destroy foobar

This will destroy jail foobar

Are you sure? [y/N]: y
Stopping foobar
Destroying foobar

@Corvan
Copy link
Contributor Author

Corvan commented Jan 28, 2019

I tried to destroy a jail which had (nullfs) mounts. I have to admit that we are not on 1.0 yet. The destruction failed with the message that zfs do datasets could not be destroyed l, but not that the jail was still running, so I thought I'd suggest the output of a hint that it is still running.
If you have issues with the code or with the approach, feel free to do with the PR as you like, I won't be disappointed. But maybe it might be good to tell the person trying to destroy it, that it is actually still running, before destroying it.

@skarekrow
Copy link
Member

@pmhausen You haven't used 1.0 yet? :O Well 1.0/1.1 prompt that they are stopping the jail (including those with nullfs mounts) and also destroys as shown in my example.

Would you prefer it doesn't destroy the jail and instead tells you the jail is running and exits? We could perhaps change the behavior that happens in my example to only occur with the force flag.

@pmhausen
Copy link

pmhausen commented Jan 30, 2019 via email

@Corvan
Copy link
Contributor Author

Corvan commented Jan 30, 2019

@skarekrow We are in the transition phase of going to 1.0/1.1 but in this case it was not 1.0 yet. I for myself would prefer being notified that the jail is still running and not have the jail destroyed. But if you have another opinion on that, I am not against the way it is now. Then I'd like to suggest "just" to get an additional warning.

Copy link
Member

@skarekrow skarekrow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will have some performance implications, I think we should handle this in iocage_lib/iocage.py instead to avoid those pitfalls

@skarekrow
Copy link
Member

@pmhausen Sorry I saw punkt.de and I assumed you were also involved with this :P

@Corvan I think that's a good idea, I left a request changes so that we can tackle that in the lib instead. I think an exception that the jail is running unless force is supplied is reasonable default behavior.

Thanks for the PR!

Copy link
Contributor Author

@Corvan Corvan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me

@Corvan
Copy link
Contributor Author

Corvan commented Jan 31, 2019

@skarekrow thanks for considering my idea

@skarekrow
Copy link
Member

@Corvan No problem, I'm fine if you want to tackle that still in this PR! After all, it was your idea :)

@Corvan
Copy link
Contributor Author

Corvan commented Feb 1, 2019

What can I do to finish it off?

@skarekrow
Copy link
Member

Well the changes I suggested should be addressed first, and then you can check for the force flag in the lib and refuse to destroy if that's the case. Instantiating the iocage lib for each of those could be slightly costly, so I think we should move this into the lib in general, help get more logic out of the cli

@Corvan
Copy link
Contributor Author

Corvan commented Feb 2, 2019

OK, I'll try. Maybe I might have some more questions, so be prepared ;-)

@skarekrow
Copy link
Member

skarekrow commented Feb 2, 2019 via email

@Corvan
Copy link
Contributor Author

Corvan commented Feb 3, 2019

So, After some hassle setting up a development environment in a VM, I moved the stuff into the lib (see https://github.com/Corvan/iocage/tree/features/destroy), But I have got a problem with the release, because destroying a release with --recursive is not using the destroy_jail-method. I could not find a way to check in the destroy_release-method to check if a jail is still running. Am I right here, or did I miss something?

@skarekrow
Copy link
Member

@Corvan Correct, in this case we should check if there are any dependents in destroy_release and stop them there or just call destroy_jail for each and then finally end by calling destroy_release.

@Corvan
Copy link
Contributor Author

Corvan commented Feb 4, 2019

If it would be feasible to call destroy_jail from destroy_release if there are dependent jails, I would go this way. I just was not sure if there is a reason why destroy_jail is not called.

@skarekrow
Copy link
Member

@Corvan That would be fine too, my memory says I didn't do that to avoid unnecessary calls/exceptions since most of the time RELEASEs are just being destroyed bare. If a user forces a release destruction, it makes sense that jails are forcefully torn down instead of stopping them in my book.

But since we're adding the rest of what you suggested, it makes sense to have it do the right thing there as well.

@Corvan
Copy link
Contributor Author

Corvan commented Feb 5, 2019

I'll look into it and will try to do it in a nice way, but this might take some days until my head is free enough again to work on this

@skarekrow
Copy link
Member

No rush :) Appreciate the PR

@pmhausen
Copy link

pmhausen commented Feb 6, 2019

Hey guys,

minor remark: similarly to this, iocage should IMHO not silently start a jail that is offline when I issue iocage console foo ...
Suggestion: error message "jail is down, use -f to force-start" or similar.

Kind regards,
Patrick

@skarekrow
Copy link
Member

@pmhausen Can you open a ticket for that and exec. Perhaps it shouldn't. My line of thinking was if you're asking iocage to console into a jail, it must start. Otherwise, not much a console ;)

This will call destroy_jail per child of the release and
with it the check if the child is still running, so that the
child only gets destroyed if it is not running. While this
introduces some effect on performance, it will only occurr
when a release has got dependent jails. When destroy_release
is called with --recursive and -f the children will be
stopped and destroyed afterwards, so that the release can be
destroyed anyways.
@Corvan
Copy link
Contributor Author

Corvan commented Feb 10, 2019

So, now I got to work on this. I am aware that this way might not be the most performant but it was the least intrusive. So I'd be interested, what you think about it.
I tried to run the tests locally but failed to get pytest running in my FreeBSD-Box, but this might be due to me not being familiar with pytest; I use unittest normally.
So when you approve i will look into writing specific tests for this case

iocage_lib/iocage.py Outdated Show resolved Hide resolved
iocage_lib/iocage.py Outdated Show resolved Hide resolved
@skarekrow skarekrow merged commit 04a0442 into iocage:master Feb 25, 2019
@skarekrow
Copy link
Member

Thanks!

@Corvan
Copy link
Contributor Author

Corvan commented Feb 26, 2019

Thank you!

skarekrow pushed a commit that referenced this pull request Sep 12, 2020
#831)

* destroy a jail only if it is not running

* destroy a jail only if it is not running

* call destroy_jail to destroy_release

This will call destroy_jail per child of the release and
with it the check if the child is still running, so that the
child only gets destroyed if it is not running. While this
introduces some effect on performance, it will only occurr
when a release has got dependent jails. When destroy_release
is called with --recursive and -f the children will be
stopped and destroyed afterwards, so that the release can be
destroyed anyways.

* fix indentation

* remove unnecessary return

* add callback
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants