2021-12-19 17:04:27 +01:00
GoCage
=======
2021-11-27 10:43:28 +01:00
2021-12-19 16:49:07 +01:00
Jail management tool for FreeBSD, written in Go.
Support iocage jails, so they can coexist.
2021-12-19 17:04:27 +01:00
Gocage is meant to be a complete jail management tool with network, snapshots, jail cloning support and a web interface. This is the hypothetic future.
2022-06-18 16:07:29 +02:00
Gocage can handle multiple datastores, so you can have jails on HDD storage and jails on SSD storage.
2023-06-03 11:18:42 +02:00
From v0.33b, due to multi ZFS pool support, gocage is no longer 100% compatible with iocage.
Zfs datasets now should be specified with the ZFS pool. e.g. :
2024-09-22 19:35:46 +02:00
<pre><code>Config.Jail_zfs = 1
2023-06-03 11:18:42 +02:00
Config.Jail_zfs_dataset = myzfspool/poudriere
Config.Jail_zfs_mountpoint = none
2023-08-06 15:12:53 +02:00
</code></pre>
2021-12-19 17:04:27 +01:00
2023-08-05 20:05:47 +02:00
Create jails
------------
2024-09-22 17:39:00 +02:00
You need to specify release, and optional configuration:
2024-09-22 19:35:46 +02:00
<pre><code>gocage create jail1 -r 13.2-RELEASE -p "Config.Ip4_addr='vnet0|192.168.1.91/24',Config.Ip6=none,Config.Boot=1"
2023-08-05 20:05:47 +02:00
</code></pre>
2024-09-22 17:49:27 +02:00
Create basejail. A basejail is a jail based on a release: system will be nullfs read-only mounted from the release directory. Main advantage is that release updates will immediately apply to jails based on this release. Another advantage is that jail system is mounted read-only, a plus from a security perspective:
2024-09-22 19:35:46 +02:00
<pre><code>gocage create -b -r 14.0-RELEASE basejail1
2023-08-06 14:54:57 +02:00
</code></pre>
2023-08-05 20:05:47 +02:00
2021-12-19 17:04:27 +01:00
List jails
----------
2024-09-22 19:39:42 +02:00
<pre><code>gocage list</code></pre>
2021-12-19 17:04:27 +01:00
### Specify fields to display
2021-12-19 16:49:07 +01:00
Use -o to specify which fields you want to display:
2024-09-22 19:35:46 +02:00
<pre><code>gocage list -o JID,Name,Running,Config.Boot,Config.Comment
2021-12-19 17:04:27 +01:00
+=====+==========+=========+=============+================+
| JID | Name | Running | Config.Boot | Config.Comment |
+=====+==========+=========+=============+================+
| 183 | test | true | 1 | none |
+-----+----------+---------+-------------+----------------+
| 29 | srv-irc | true | 1 | |
+-----+----------+---------+-------------+----------------+
| | srv-web | false | 0 | |
+-----+----------+---------+-------------+----------------+
| 22 | srv-dns1 | true | 1 | |
+-----+----------+---------+-------------+----------------+
</code></pre>
2024-09-22 19:47:37 +02:00
Use `gocage properties` to list available fields.
2021-12-19 17:04:27 +01:00
Filter jails
----------
2021-12-19 16:49:07 +01:00
### By name
Just add name on gocage list command :
2024-09-22 19:35:46 +02:00
<pre><code>gocage list srv-bdd srv-web
2021-12-19 17:04:27 +01:00
+=====+=========+=================+=======================+=========+
| JID | Name | Config.Release | Config.Ip4_addr | Running |
+=====+=========+=================+=======================+=========+
| 98 | srv-db | 13.0-RELEASE-p5 | vnet0|192.168.1.56/24 | true |
+-----+---------+-----------------+-----------------------+---------+
| 41 | srv-web | 13.0-RELEASE-p4 | vnet0|192.168.1.26/24 | true |
+-----+---------+-----------------+-----------------------+---------+
2024-09-22 19:39:42 +02:00
</code></pre>
2021-12-19 16:49:07 +01:00
### By field value
You can filter jails with -f option, followed by key=value. Suppose you want to see only active at boot jails:
2024-09-22 19:35:46 +02:00
<pre><code>gocage list -f Config.Boot=1 -o JID,Name,Running,Config.Boot,Config.Comment
2021-12-19 17:04:27 +01:00
+=====+==========+=========+=============+================+
| JID | Name | Running | Config.Boot | Config.Comment |
+=====+==========+=========+=============+================+
| 183 | test | true | 1 | none |
+-----+----------+---------+-------------+----------------+
| 29 | srv-irc | true | 1 | |
+-----+----------+---------+-------------+----------------+
| | srv-db | false | 1 | none |
+-----+----------+---------+-------------+----------------+
| 22 | srv-dns1 | true | 1 | |
+-----+----------+---------+-------------+----------------+
2024-09-22 19:39:42 +02:00
</code></pre>
2021-12-19 17:04:27 +01:00
2021-12-19 16:49:07 +01:00
Now, only active at boot and running :
2024-09-22 19:35:46 +02:00
<pre><code>gocage list -f Config.Boot=1,Running=true -o JID,Name,Running,Config.Boot
2021-12-19 17:04:27 +01:00
+=====+==========+=========+=============+
| JID | Name | Running | Config.Boot |
+=====+==========+=========+=============+
| 183 | test | true | 1 |
+-----+----------+---------+-------------+
| 29 | srv-irc | true | 1 |
+-----+----------+---------+-------------+
| 22 | srv-dns1 | true | 1 |
+-----+----------+---------+-------------+
2024-09-22 19:39:42 +02:00
</code></pre>
2021-12-19 17:04:27 +01:00
2021-12-20 22:16:36 +01:00
Sort jails
----------
Use -s switch followed by sort criteria. Criteria is a field name, prefixed with + or - for sort order (increase/decrease):
2024-09-22 19:35:46 +02:00
<pre><code>gocage list -f Config.Boot=1,Running=true -o JID,Name,Running,Config.Boot -s +JID
2021-12-20 22:16:36 +01:00
+=====+==========+=========+=============+
| JID | Name | Running | Config.Boot |
+=====+==========+=========+=============+
| 22 | srv-dns1 | true | 1 |
+-----+----------+---------+-------------+
| 29 | bdd-tst | true | 1 |
+-----+----------+---------+-------------+
| 183 | test | true | 1 |
+-----+----------+---------+-------------+
2024-09-22 19:39:42 +02:00
</code></pre>
2021-12-20 22:16:36 +01:00
2021-12-20 22:23:17 +01:00
You can use up to 3 criteria, delimited with comma.
As an example, you want to list boot priorities of automatically starting jails:
2024-09-22 19:35:46 +02:00
<pre><code>gocage list -o JID,Name,Config.Ip4_addr,Config.Priority,Config.Boot,Running -s -Config.Priority,-Config.Boot -f Running=true
2021-12-20 22:23:17 +01:00
+=====+==============+=======================+=================+=============+=========+
| JID | Name | Config.Ip4_addr | Config.Priority | Config.Boot | Running |
+=====+==============+=======================+=================+=============+=========+
| 1 | srv-dhcp | vnet0|192.168.1.2/24 | 99 | 1 | true |
+-----+--------------+-----------------------+-----------------+-------------+---------+
| 8 | srv-dns | vnet0|192.168.1.1/24 | 80 | 1 | true |
+-----+--------------+-----------------------+-----------------+-------------+---------+
| 7 | srv-random | vnet0|192.168.1.12/24 | 20 | 1 | true |
+-----+--------------+-----------------------+-----------------+-------------+---------+
| 4 | coincoin | vnet0|192.168.1.9/24 | 20 | 0 | true |
+-----+--------------+-----------------------+-----------------+-------------+---------+
2024-09-22 19:39:42 +02:00
</code></pre>
2021-12-20 22:16:36 +01:00
2023-07-09 10:52:12 +02:00
Stop jails
2021-12-19 17:04:27 +01:00
----------
2024-09-22 19:39:42 +02:00
<pre><code>gocage stop test</code></pre>
2021-12-19 16:49:07 +01:00
2023-07-09 10:52:12 +02:00
Update jails
----------
To update jail patch version, use gocage update :
2024-09-22 19:39:42 +02:00
<pre><code>gocage update test</code></pre>
2023-07-09 10:52:12 +02:00
2024-09-22 19:30:43 +02:00
Update basejails/releases
----------
2024-09-22 19:32:07 +02:00
To update basejails, you need to update the release they are based on. Specify release with -r, and the datastore storing concerned release with -d :
2024-09-22 19:39:42 +02:00
<pre><code>gocage update -d fastgocage -r 14.1-RELEASE</code></pre>
2023-07-09 10:52:12 +02:00
2023-08-05 20:05:47 +02:00
Upgrade jails
----------
To upgrade jail to newer release, use gocage upgrade :
2024-09-22 19:39:42 +02:00
<pre><code>gocage upgrade -r 13.2-RELEASE test</code></pre>
2023-08-05 20:05:47 +02:00
2024-09-22 19:30:43 +02:00
A pre-upgrade snapshot wil be made so you can rollback if needed.
2023-08-05 20:05:47 +02:00
2024-09-22 19:30:43 +02:00
Upgrading basejail/release
----------
Upgrading basejails currently needs to be done manually, for each jail.
The idea is to stop the jail, change the content of its fstab file to point to the new release, then start jail.
If one change the fstab while the jail is running, its system directories won't be unmounted at stop time and this will provoke stop errors.
To minimize downtime, the change could be scripted:
2024-09-22 19:35:46 +02:00
<pre><code>gocage stop jail1
2024-09-22 19:30:43 +02:00
sed -i .bak 's/14.0-RELEASE/14.1-RELEASE/' /iocage/jails/jail1/fstab
# Avoid race-condition by waiting for the update in fstab
until grep -q 14.1-RELEASE /iocage/jails/jail1/fstab; do sleep 0.2; done
2024-09-22 19:32:07 +02:00
gocage start jail1
2024-09-22 19:35:46 +02:00
</code></pre>
2024-09-22 19:30:43 +02:00
You can now update ports.
2023-08-05 20:05:47 +02:00
2023-07-09 13:43:35 +02:00
Delete jails
----------
2024-09-22 19:39:42 +02:00
<pre><code>gocage destroy test</code></pre>
2023-07-09 13:43:35 +02:00
2022-06-18 16:07:29 +02:00
Multi datastore
----------
A datastore is a ZFS dataset mounted. It should be declared in gocage.conf.yml, specifying its ZFS mountpoint :
2024-09-22 19:35:46 +02:00
<pre><code>datastore:
2022-06-18 16:07:29 +02:00
- /iocage
- /fastiocage
2024-09-22 19:39:42 +02:00
</code></pre>
2022-06-18 16:07:29 +02:00
In gocage commands, datastore name is the mountpoint without its "/" prefix.
### List datastores
2024-09-22 19:35:46 +02:00
<pre><code>gocage datastore list
2022-06-18 16:07:29 +02:00
+============+=============+============+===========+==========+============+
| Name | Mountpoint | ZFSDataset | Available | Used | Referenced |
+============+=============+============+===========+==========+============+
| iocage | /iocage | hdd/iocage | 1.6 TB | 414.9 GB | 27.5 KB |
+------------+-------------+------------+-----------+----------+------------+
| fastiocage | /fastiocage | ssd/iocage | 1.5 TB | 65.3 KB | 34.6 KB |
+------------+-------------+------------+-----------+----------+------------+
2024-09-22 19:39:42 +02:00
</code></pre>
2022-06-18 16:07:29 +02:00
2022-10-15 15:23:58 +02:00
### Filter datastores
2022-06-18 16:07:29 +02:00
As with jails and snapshots, you can filter by name:
2024-09-22 19:35:46 +02:00
<pre><code>gocage datastore list iocage
2022-06-18 16:07:29 +02:00
+============+=============+============+===========+==========+============+
| Name | Mountpoint | ZFSDataset | Available | Used | Referenced |
+============+=============+============+===========+==========+============+
| iocage | /iocage | hdd/iocage | 1.6 TB | 414.9 GB | 27.5 KB |
+------------+-------------+------------+-----------+----------+------------+
2024-09-22 19:39:42 +02:00
</code></pre>
2022-06-18 16:07:29 +02:00
2022-10-15 15:23:58 +02:00
### Sort datastores
2022-06-18 16:07:29 +02:00
You can sort datastores:
2024-09-22 19:35:46 +02:00
<pre><code>gocage datastore list -s -Available
2022-06-18 16:07:29 +02:00
+============+=============+============+===========+==========+============+
| Name | Mountpoint | ZFSDataset | Available | Used | Referenced |
+============+=============+============+===========+==========+============+
| iocage | /iocage | hdd/iocage | 1.6 TB | 415.0 GB | 27.5 KB |
+------------+-------------+------------+-----------+----------+------------+
| fastiocage | /fastiocage | ssd/iocage | 1.5 TB | 65.3 KB | 34.6 KB |
+------------+-------------+------------+-----------+----------+------------+
2024-09-22 19:39:42 +02:00
</code></pre>
2022-06-18 16:07:29 +02:00
2024-09-22 19:47:37 +02:00
Use `gocage properties` to list available fields.
2022-06-18 16:07:29 +02:00
Migrating jails
----------
With multi datastore comes the need to migrate a jail between datastores.
Migration can be done with a minimal downtime, using zfs differential send/receive.
Source jail datasets are sent to the destination datastore, jail is stopped and a last differential sync is done before starting jail on new datastore.
2022-10-15 15:23:58 +02:00
### Warning
Be aware the moment you migrate a jail to another datastore than /iocage default, you lose compatibility with iocage.
Then you need to disable iocage service, and enable gocage so the jails will start automatically at boot.
Also make sure, if you don't destroy source jail, that it won't have the "boot" property set or you will have the 2 jails up at boot.
2024-09-22 19:35:46 +02:00
<pre><code>gocage migrate -d fastiocage srv-random
2022-06-18 16:07:29 +02:00
Snapshot data/iocage/jails/srv-random: Done
Snapshot data/iocage/jails/srv-random/root: Done
Migrate jail config dataset to fastdata/iocage/jails/srv-random: Done
Migrate jail filesystem dataset to fastdata/iocage/jails/srv-random/root: Done
2024-09-22 19:39:42 +02:00
</code></pre>
2022-10-15 15:23:58 +02:00
2022-10-15 16:38:17 +02:00
2022-11-06 16:34:52 +01:00
Fetch
----------
Files can be fetched from custom repository, or from local directory with "from" option.
For example if you destroyed releases/12.3-RELEASE and still have the downloaded files in /iocage/download/12.3-RELEASE:
2024-09-22 19:35:46 +02:00
<pre><code>gocage fetch -r 12.3 -d iocage -f file:/iocage/download
2024-09-22 19:39:42 +02:00
</code></pre>
2022-11-06 16:34:52 +01:00
2022-10-15 16:38:17 +02:00
TODO
----------
2023-08-05 20:06:38 +02:00
gocage create from templates
2024-09-22 19:37:31 +02:00