unRAID V6 Plugins
I started out asking how the plugin system works, and while implementing some plugins, I learned a lot about how it works.
V6b8 has brought in a totally new plugin system compared to V5 that is more flexible, easier to use, and helps sort out the "What plugins do I have installed and what versions are they?" questions. While I don't profess to be an expert at the plugin system, I wanted to start a post to help those wanting to convert V5 plugins or author new plugins.
If the plugins follow the proper structure, the plugin manager (plgman) can check for the latest version, update, and remove plugins cleanly while unRAID is on-line.
There are some best practices to be followed with the new plgman.
Install plugins in the "Install Extensions" field in the "Extensions" tab. Don't install plugins by putting then in the flash drive. Plgman needs to manage the plugin for proper operation. You can enter a URL or a plugin file on unRAID to install.
Remove plugins through the plgman webpage.
Use plgman to update plugins.
I will use the ntfs-3g plugin I wrote for V6 as an example. It does not have a webpage in unRAID, but I'll go through what needs to be done so unRAID will understand how to use the webpage.
Start off in your plug in with:
<?xml version='1.0' standalone='yes'?>
<!DOCTYPE PLUGIN [
<!ENTITY name "ntfs-3g">
<!ENTITY author "dlandon">
<!ENTITY version "2014.09.05">
<!ENTITY pluginURL "https://github.com/dlandon/unraid-snap/raw/master/ntfs-3g-x86_64.plg">
]>
<PLUGIN name="&name;"
author="&author;"
version="&version;"
pluginURL="&pluginURL;">
The describes your plugin to the unRAID plgman.
name - this is the name of you plugin. This name should be the sub-directory for you plugin off the /usr/local/emhttp/plugins/ directory and is where your plugin files are located. Plgman uses the name to find your plugin, and the icon associated with the plugin. The icon should be named 'name.png'. Plgman uses this information to display information about your plugin.
author - Information field for plgman to display.
version - Plgman displays the version and uses this version to check for an updated version in your repository. The convention is year.month.day. If several releases occur in the same day, use the convention year.month.day-x, where x-=1,2,...
pluginURL - The is the web URL to the repository where your plugin is stored. Plgman uses it to look for the latest version of your plugin. It is best to use a generic name for your plugin and not have the name include a version. The versioning is done inside the plugin.
<!--
2013-10-19 - first release
2014-01-24 - Modified for unRAID 6 (64 bit)
The plugin provides ntfs-3g support for unRAID systems.
-->
It is a good idea to include some comments or further information about the plugin. This would be a good place for a license.
<FILE Name="/boot/packages/ntfs-3g-2013.1.13-x86_64-1.txz" Run="upgradepkg --install-new">
<URL>http://slackware.oregonstate.edu/slackware64-14.1/slackware64/a/ntfs-3g-2013.1.13-x86_64-1.txz</URL>
<MD5>de646f44d881b6c4292e353b717792cd</MD5>
</FILE>
This is the ntfs-3g package that is installed. This could be a tar bundle that you expand into the the /usr/local/enhttp/plugins/name. If you download a tar bundle, store a copy on the flash at /boot/config/plugins/name so it doesn't have to be downloaded each time the plugin is installed. Packages are stored on the flash at /boot/packages.
<FILE Name="/boot/config/plugins/&name;/ntfs-3g.png">
<URL>https://github.com/dlandon/unraid-snap/raw/master/ntfs-3g.png</URL>
</FILE>
This is the icon used for the ntfs-3g plugin. I would recommend that you put this into the bundle for the plugin structure you download if possible.
<FILE Name="/usr/local/emhttp/plugins/&name;/ntfs-3g.png">
<LOCAL>/boot/config/plugins/&name;/ntfs-3g.png</LOCAL>
</FILE>
This does nothing more than make a copy of the stored ntfs-3fg icon on the flash drive into the plugin file structure.
<!--
Page file
-->
<FILE Name="/usr/local/emhttp/plugins/&name;/Apcupsd.page">
<INLINE>
<![CDATA[
Menu="OtherSettings"
Icon="apcupsd.png"
Version="2014.09.06"
Author="SeeDrs"
Title="APC UPS"
---
<?php
php goes here.
?>
]]>
</INLINE>
</FILE>
Plugin Page File
The page file is used by emhttp to display and render your webpage. The page file must begin with a capital letter, and your php included in the page file. This is the page file from the Apcupsd plugin as an example. The 'Menu' setting is important because this is the area in 'Settings' where emhttp will install the icon.
<!--
create plugin README.md file
-->
<FILE Name="/usr/local/emhttp/plugins/&name;/README.md">
<INLINE>
**NTFS-3G Package**
The ntfs-3g driver package is needed for writing on NTFS formated disks. The built in NTFS driver is read only.
</INLINE>
</FILE>
README File
The READ.me is used by plgman to dispay in the plugin webage. Use it to describe your plugin. Again, I recommend that you put this file in your tar bundle if it is possible to save this step.
Remove Method
<!--
The 'remove' script.
-->
<FILE Run="/bin/bash" Method="remove">
<INLINE>
rm /boot/packages/ntfs-3g-2013.1.13-x86_64-1.txz
removepkg &name;
rm -r /usr/local/emhttp/plugins/&name;
rm -r /boot/config/plugins/&name;
</INLINE>
</FILE>
</PLUGIN>
This is the remove script executed when plgman is asked to remove the plugin. Do any package removal and clean up necessary to remove all traces of the plugin.
There are some cli commands that you can use for development and testing of your plugin:
plugin install - Install the plugin.
plugin delete name - This is how you remove a plugin. The 'name' is the name of your plugin.
plugin update name - This will update your plugin. If you have made changes to the plugin, this will re-install the plugin with your changes. This is how plgman does a plugin update. It downloads the new plugin first, then runs the update.
plugin check name - Check for a new version of your plugin.
I know this is not complete and I would like input from Tom or Jonp if there is anything I need to correct/add. I would rather them spend time on the core functionality at this point and not spend their time on documentation.
UPDATE:
V6 beta11 has depricated 'category'. It is no longer used.
The emhttp file structure in beta 12 has been changed. You can no longer have a .page file with a separate .php file of the same name. Your php is expected in the .page file. The php is separated in the .page file with '---'. The following is a work around to this limitation. This is the Snap.page from the updated snap plugin.
Menu="OtherSettings"
Icon="snap.png"
Version="6.04"
Author="Queeg/dlandon"
Title="SNAP"
---
<?php
shell_exec('php /usr/local/emhttp/plugins/snap/Snap.php');
?>
Dynamix
V6b12 incorporated dynamix as the default webgui. Dynamix has a process status indicator built into every plugin webpage you can use. This is how I did it in the apcupsd plugin:
$sName = "apcupsd";
<script>
$(function() {
showStatus('<?=$sName?>');
});
</script>
Dynamix checks for the existence of the pid file 'apcupsd.pid' and shows 'Running' if it exists, and 'Stopped' if it is not found. You should incorporate this indicator to be consistent with other dynamix web pages.
This should be put at a place in your page refresh where the pid status would be valid.
Notifications
v6b12 now has an email and webgui notification system.
/usr/local/sbin/notify -e "title of the message" -s "subject of the message" -d "additional information" -i "normal"
The -i parameter specificies the importance level: normal, warning or alert
Tabbed Menu
Dynamix has rhe ability to use a tabbed system for plugins. The following is from the apcupsd plugin:
Acpupsd.page
Menu="OtherSettings"
Title="APC UPS"
Type="xmenu"
Icon="apcupsd.png"
Tabs="true"
---
ApcupsdSettings.page
u="Apcupsd:1"
Title="UPS Settings"
---
<?PHP
ApcupsdStatus.page
Menu="Apcupsd:2"
Title="UPS Status"
---
<?PHP
Changelog
A changelog can be displayed after the check for updates. Add the following to the plugin to display the changelog:
<CHANGES>
###2014-12-07
- Made a change
- Made another change
</CHANGES>