Auto update jails script

Status
Not open for further replies.

ezra

Contributor
Joined
Jan 15, 2015
Messages
124
I needed a way to auto update all my jails without the need to edit the script when I delete or add jails. The last script on the forum was a little outdated and did not add jails automatically.

This will grep all jails by name and update, upgrade, pkg upgrade/update and restart the jails if needed.

Please advise if you have any pointers to make the script better.
FreeNAS 11.2 beta-1 / iocage jails.

Code:
#!/bin/bash
VERSION=$(freebsd-version | sed 's|STABLE|RELEASE|g')
declare -a vars
eval "vars=(`/usr/local/bin/iocage list | awk '{ print $4 }' | sed '2d' | grep .`)"
for ((I = 0; I < ${#vars[@]}; ++I )); do
	/usr/local/bin/iocage update "${vars[$I]}"
	/usr/local/bin/iocage upgrade "${vars[$I]}" -r "$VERSION"
	  if /usr/local/bin/iocage exec "${vars[$I]}" "pkg update && pkg upgrade" | grep -q 'Your packages are up to date.'; then
		echo "No need to restart jails"
	  else
		/usr/local/bin/iocage restart "${vars[$I]}"
	  fi
done
 
Last edited:

8-bit Yoda

Explorer
Joined
Jun 16, 2018
Messages
68
The /usr/local/bin/iocage upgrade part doesn't make sense to me, as this command needs a target release; iocage upgrade is intended to upgrade the jail's current release (e.g. from 11.1-RELEASE) to a specified release (e.g. 11.2-RELEASE), where iocage update updates the jail's current release to the latest patch level, e.g. from 11.1-RELEASE-P9 to 11.1-RELEASE-p11.

Also, if you have a mix of regular (clone) jails and plugins or even base jails, you should take the jail's type into account, as for the latter iocage update doesn't make sense either (or may not work as you think it does).
 

ezra

Contributor
Joined
Jan 15, 2015
Messages
124
I dont have clones, so thats no issue for me. See the updated code.
 

nuneya

Dabbler
Joined
Jul 25, 2018
Messages
17
The /usr/local/bin/iocage upgrade part doesn't make sense to me, as this command needs a target release; iocage upgrade is intended to upgrade the jail's current release (e.g. from 11.1-RELEASE) to a specified release (e.g. 11.2-RELEASE), where iocage update updates the jail's current release to the latest patch level, e.g. from 11.1-RELEASE-P9 to 11.1-RELEASE-p11.

Also, if you have a mix of regular (clone) jails and plugins or even base jails, you should take the jail's type into account, as for the latter iocage update doesn't make sense either (or may not work as you think it does).

Can you elaborate on your iocage update/upgrade points? Why would it not make sense to run?
 

ezra

Contributor
Joined
Jan 15, 2015
Messages
124
It did work fine when Freenas went from 11.1 to 11.2, without me having to manually do it. I'm keeping this script.

@nuneya thanks for the tip. It does make it better, but I'd still have to figure out what to cut out :P I'll stick to the hour I put into it ;)
 
Status
Not open for further replies.
Top