Register for the iXsystems Community to get an ad-free experience and exclusive discounts in our eBay Store.
Resource icon

Create an unofficial iocage plugin

Western Digital Drives - The Preferred Drives of FreeNAS and TrueNAS CORE
Scope
This resource will walk you through the process of setting up an iocage plugin. The intent is to familiarize people with the basic layout of an iocage plugin, so that they start building plugins and contribute to them community. :)

Note that there’s way more to plugins that is mentioned in this document. For more information, please refer to the official documentation: https://doc.freenas.org/11.2/plugins.html#create-a-plugin
Assumptions
Prerequisites:
  • You have a GitHub account
  • You have access to an 11.2 FreeNAS system
  • You can do basic navigation and file management using the command line
Recommended:
  • Please don’t do any of this as root, but set up a user in wheel with sudo permission
  • Use a proper SSH cllient
The below was produced and tested on a laptop using Firefox and running FreeNAS-11.2-MASTER-201809080900 in VirtualBox
Process
In this exercise, we will create a simple plugin to play Tetris.
We will create an iocage jail, install some packages and then configure and start the relevant service.

Step #1 Create artifact repository
We start by creating the artifact repository called iocage-plugin-tetris. The artifact repository is used to hold scripts, files and other resources that come into play after the jail is created and packages are installed.
Go to https://github.com/new, logon if needed, chose New Repository, enter the following information and click Create
upload_2018-9-10_23-6-28.png

You could edit/add the various files directly in your browser, but I prefer to clone this repository to my local system and then push my changes back.
Get the URL of the repo you just created by clicking the Clone or download button and pick the Clone with HTTPS option.

Now Go to your FreeNAS command line and clone the repo:
Code:
jurgen@freenas:~ % git clone https://github.com/jsegaert/iocage-plugin-tetris.git
Cloning into 'iocage-plugin-tetris'...
remote: Counting objects: 7, done.
remote: Compressing objects: 100% (5/5), done.
remote: Total 7 (delta 0), reused 4 (delta 0), pack-reused 0
Unpacking objects: 100% (7/7), done.

jurgen@freenas:~ % ls
iocage-plugin-tetris

jurgen@freenas:~ % cd iocage-plugin-tetris/
jurgen@freenas:~/iocage-plugin-tetris % ls
post_install.sh README.md	   ui.json

In this directory, create a new file post_install.sh with the following content:
Code:
#!/bin/sh

# Create user 'tetris'
pw add user -n tetris -c Tetris -s /bin/csh -m

# Configure shellinabox
fetch -o /home/tetris/white-on-black.css https://raw.githubusercontent.com/shellinabox/shellinabox/master/shellinabox/white-on-black.css
sysrc shellinaboxd_enable=YES
sysrc shellinaboxd_flags="--css /home/tetris/white-on-black.css -t -s /:tetris:tetris:HOME:bastet"

# Start the service
service shellinaboxd start

Make sure to make it executable by running chmod +x post_install.sh

The shellinaboxd service will run program bastet on http://<IP of jail>:4200/. To link this URL to the Management link in the UI, we create a file ui.json with the following content:
Code:
{
		"adminportal": "http://%%IP%%:4200/"
}

That’s it! Before pushing the changes back to GitHub, set your user name and email address in git. (This is a one-time activity if you pass the --global option)
Code:
git config --global user.name "<Your github user name>"
git config --global user.email "<Your GitHub email address>"

Now commit your changes and push them back to GitHub. Enter your Github credentials when it prompts for them.
Code:
git add .
git commit -m "Initial commit"
git push origin master

The end result should look similar to this: https://github.com/jsegaert/iocage-plugin-tetris

Step #2 Create manifest file
The manifest is a JSON file that contains all the information iocage needs to create the jail and the list of packages to be installed.
Create a new file tetris.json in any directory (don't put in iocage-plugin-tetris) with the following content:
Code:
{
  "name": "tetris",
  "release": "11.1-RELEASE",
  "artifact": "https://github.com/jsegaert/iocage-plugin-tetris.git",
  "properties": {
	"allow_raw_sockets":"1",
	"boot":"on"
	  },
  "pkgs": [
	"games/bastet",
	"security/ca_root_nss",
	"www/shellinabox"
	  ],
  "packagesite": "http://pkg.FreeBSD.org/FreeBSD:11:amd64/quarterly",
  "fingerprints": {
		  "plugin-default": [
				  {
				  "function": "sha256",
				  "fingerprint": "b0170035af3acc5f3f3ae1859dc717101b4e6c1d0a794ad554928ca0cbb2f438"
			  }
			]
	},
	"official": false
}

The end result should look like this: https://raw.githubusercontent.com/jsegaert/iocage-my-plugins/master/tetris.json

The content is almost self-explanatory:
  • name (required) This will be the name of the jail, note that iocage will automatically convert the name to lowercase. Avoid periods/dots and underscore characters in the name.
  • release (required) You shouldn't pick a release that is newer than the one of the FreeNAS host. Get a list by running iocage list --remote or iocage list -R
  • artifact [required] Link to GitHub artifact repository, as created above
  • properties [optional] Set various iocage attribute as specified, otherwise it will just use the default iocage attibutes /iocage/defaults.json. Note that any properties specified at the CLI will override the properties in the json file.
  • pkgs (required, but may be empty) List of packages that will be installed.
  • packagesite Package repository that will be used to install packages above, examples:
    http://pkg.cdn.trueos.org/iocage (the standard repo used for official plugins)
    http://pkg.FreeBSD.org/FreeBSD:11:amd64/latest (Vanilla FreeBSD pkg repo, latest)
    http://pkg.FreeBSD.org/FreeBSD:11:amd64/quarterly (Vanilla FreeBSD pkg repo, quarterly)
  • fingerprints (required) fingerprint and method for signing the pkg repo above.
    For the vanilla FreeBSD repo, use b0170035af3acc5f3f3ae1859dc717101b4e6c1d0a794ad554928ca0cbb2f438
    For iXSystems repo, use 226efd3a126fb86e71d60a37353d17f57af816d1c7ecad0623c21f0bf73eb0c7
  • Official Boolean to distinguish “official” versus “community” plugins
Step #3 Install the plugin locally
Finally, install the plugin. All you need is that JSON manifest file and some network information. Currently you need to install/create from the command line, but a feature request exists that will let you install a local plugin from the UI.

Code:
jurgen@freenas:~ % sudo iocage fetch -P -n tetris.json ip4_addr="em0|192.168.0.220/24"
Password:
Plugin: tetris
  Official Plugin: False
  Using RELEASE: 11.1-RELEASE
  Using Branch: 11.2-RELEASE
  Post-install Artifact: https://github.com/jsegaert/iocage-plugin-tetris.git
  These pkgs will be installed:
	- games/bastet
	- security/ca_root_nss
	- www/shellinabox

Testing SRV response to plugin-default
Testing DNSSEC response to plugin-default

Installing plugin packages:
  - games/bastet...
  - security/ca_root_nss...
  - www/shellinabox...

Fetching artifact...

Branch 11.2-RELEASE does not exist at https://github.com/jsegaert/iocage-plugin-tetris.git!
Using "master" branch for plugin, this may not work with your RELEASE

Running post_install.sh

Command output:
shellinaboxd_enable:  -> YES
shellinaboxd_flags:  -> --css /home/tetris/white-on-black.css -t -s /:tetris:tetris:HOME:bastet
Starting shellinaboxd.

Admin Portal:
http://192.168.0.220:4200/

Your plugin will now show up under "Installed Plugins" and also "Jails", woohoo.


Submit to iXSystems
To have the plugin included in the official INDEX file, fork https://github.com/freenas/iocage-ix-plugins and submit a pull request with:
  • the new plugin.json file.
  • the plugin icon .png added to the icons/ directory.
  • an update to the INDEX file with an entry for the new plugin.
  • a link to the artifact repository populated with all required plugin files.
Author
Jurgen Segaert
Views
3,326
First release
Last update
Rating
4.50 star(s) 2 ratings

Latest reviews

Thanks for the guide! I went from not having a clue what to do; to creating a plugin within an hour.
A few tiny changes to language in some places would make this great for newbies.

Recommend adding a section at the top, regarding Git, which says "if you're new to Git, make an account and follow the 'hello-world' tutorial"

Thanks for hard work
Top