Jails are not shutdown during reboot?!

Ludwig

New Member


Messages: 12

I am new to FreeBSD and experimenting with jails. I have two jails configured with jail and ezjail. These jails should always getting started if the computer boots. If I reboot my computer the jails are sometimes not started and I get this message during the boot up sequence.
Code:
Starting jails: [jailname already running (/var/run/jail_jailname.id exists)]
I have a suspicion that the shutdown command is not send to the jails. The processes in the jail are just killed by the host and the lock file gets not removed. How can I be sure that the jails are always running if I start the computer? I am running FreeBSD 9.3-RELEASE-p9.
 

junovitch@

Daemon
Developer

Reaction score: 632
Messages: 1,773

By default, /bin/sh /etc/rc.shutdown is called by /etc/rc.d/jail to shutdown jails gracefully. However, that is only called when shutdown -r now is used instead of reboot. This is a little FreeBSD nuance with the reboot(8) command.
Normally, the shutdown(8) utility is used when the system needs to be
halted or restarted, giving users advance warning of their impending doom
and cleanly terminating specific programs.

Basically reboot just has the init(8) process terminate everything while shutdown(8) calls /etc/rc.shutdown which asks this to shut down gracefully. Generally use shutdown -r now to reboot and shutdown -p now to power off.
 

wblock@

Beastie Himself
Developer

Reaction score: 3,732
Messages: 13,851

Dan Langille pointed out that ezjail does not run /etc/rc.shutdown by default. To do that, this needs to be added to the jail configuration file in /usr/local/etc/ezjail/jailname:
Code:
export jail_dns1_exec_stop="/bin/sh /etc/rc.shutdown"
 

junovitch@

Daemon
Developer

Reaction score: 632
Messages: 1,773

Another way, just so you don't have to remember to add it to each jail:
echo 'ezjail_exec_stop="/bin/sh /etc/rc.shutdown"' >> /usr/local/etc/ezjail.conf
 

gkontos

Daemon

Reaction score: 488
Messages: 2,160

I have seen many people coming from the Linux world using reboot instead of shutdown -r now. Is there any real advantage of reboot other than in single user mode?
 

wblock@

Beastie Himself
Developer

Reaction score: 3,732
Messages: 13,851

Er... it is quicker because it doesn't have to wait for services to shut down?
 

Kiiski

Active Member

Reaction score: 35
Messages: 110

Dan Langille pointed out that ezjail does not run /etc/rc.shutdown by default. To do that, this needs to be added to the jail configuration file in /usr/local/etc/ezjail/jailname:
Code:
export jail_dns1_exec_stop="/bin/sh /etc/rc.shutdown"

Another way, just so you don't have to remember to add it to each jail:
echo 'ezjail_exec_stop="/bin/sh /etc/rc.shutdown"' >> /usr/local/etc/ezjail.conf

From man page ezjail(7):

jail_JAILNAME_exec_stop
The command to run inside the jail when stopping it. Defaults to
the empty string, which means ``/bin/sh /etc/rc.shutdown''.

So according to man page ezjail should run /etc/rc.shutdown by default, shouldn't it?
 
Last edited by a moderator:

gkontos

Daemon

Reaction score: 488
Messages: 2,160

It should. My jails are usually configured manually without the use of a utility because I am a masochist. But I never use reboot in FreeBSD.
 

junovitch@

Daemon
Developer

Reaction score: 632
Messages: 1,773

From man page ezjail(7):

jail_JAILNAME_exec_stop
The command to run inside the jail when stopping it. Defaults to
the empty string, which means ``/bin/sh /etc/rc.shutdown''.

So according to man page ezjail should run /etc/rc.shutdown by default, shouldn't it?

That's a good catch. It also makes sense that it's blank by default if that is the default behavior. I did a quick search and found this on the topic:

https://elektropost.org/ezjail/msg00800.html
 

dvl@

Aspiring Daemon
Developer

Reaction score: 103
Messages: 609

This has been biting me lately.

Everytime I shutdown my Ubuiqity Unifi controller jail, it would not start up properly. I suspected a database issue. The only want to recover from was a database backup.

This is far from ideal.

I suspect others are also being bitten.

Is it time for this to be the default? Claims are made above that it is the default, but clearly it is not.

My fix was:

Code:
$ grep stop unifi01 
export jail_unifi01_exec_stop="/bin/sh /etc/rc.shutdown"

I also added this to /usr/local/etc/ezjail.conf:

Code:
ezjail_exec_stop="/bin/sh /etc/rc.shutdown"
 
Top