One PLG file to rule them all?


limetech

Recommended Posts

There are basically two ways to approach plugin design:

 

1. Create a single PLG file that has all the various files you need defined therein.

or

2. Create a github repo that contains all your files along with a minimal PLG file.

 

In all but the simplest plugins we highly suggest you adopt the second approach.  For one thing this makes your plugin easier to read and maintain.  You have a nice git history and you can let others contribute.  To see how the PLG file works for this method, take a look at the dockerMan plugin.

 

Another reason to go with method 2 - The way "plugin update" works is that it downloads the PLG file to /tmp directory.  Once download completes it executes 'plugin version' to get the version number and compares against installed version number.  The larger the PLG file, the longer this download can take (though admittedly it's probably negligible).

 

Finally, always ask yourself: is this functionality best implemented in a Docker container?  In almost all cases the answer will probably be "Yes".  In unRAID-6, plugins should only be used to extend 'core functionality' of the core OS.  As such they carry far more security risk as well.

Link to comment

I too have been discouraging the "pop-in" method of plugin installation.  Plgman does a much better job.  It's easier and cleaner.

 

You need to understand some history here.  The Apcupsd plugin was put together initially by SeeDrs as a 5.x plugin.  I believe he is no longer active on the forum.  Some forum members have added fixes and enhancements.  Powerdown was put together by WeeboTech to handle situations where the array would not stop and would get stuck in the unmounting loop on shutdown - UPS initiated, or power down button.  A UPS initiated shutdown needs to culminate in a shutdown of unRAID and not get hung in the unmounting loop.  Powerdown shuts down plugins and anything outside the core of unRAID that is keeping drives from being unmounted.  Because of the add-ons and plugins that needed to be stopped, or shutdown, Dynamix also loads the powerdown plugin.  Each plugin was installing its own version of powerdown and things got quite messy.

 

While the purist in me says all these extra gyrations should not be necessary, the plugin situation on 5.x was pretty much the wild west and something needed to be added to handle all the stuff users were loading onto unRAID.  This has now migrated to V6 because of the need for a UPS interface.  I implemented the plugin in V6 style, but limited the re-write.

 

I see the plugins that I am maintaining here have one of two outcomes:

- unRAID handles the UPS interface, unRAID shutdown, and shutting down all the add on stuff users throw at unRAID negating the need for these Apcupsd and powerdown plugins.

- Apcupsd and powerdown become core functionality.

 

I do appreciate your criticism of the plugin architecture.  I'm not fond of how it is currently implemented.  It should be as you suggest in a tar that is downloaded from a repository once and maintained in the packages directory on the flash.  I don't have the spare time to invest in re-writing these plugins if they are to become obsolete, but I am willing to spend the time if there is a need for this longer term.  This is totally your call.  Is this a good time to ask for a raise boss?

 

I don't see how Apcupsd and powerdown can practically become Dockers.

Link to comment

I have converted a few plgs to the number 2 method. I must say not having a 1000 line plus plg is nice. And it was really easy once you do it once. One thing I haven't had time to look at is after an update a stale is created. And maybe that is cause it's geared towards built-ins.

 

A plugin 'update' actually consists of two steps:

1. plgMan first invokes "plugin check <name.plg>" - this downloads a new copy of the plg file from the url specified in the plg file, to /tmp directory.  The version of the newly downloaded plg file is checked against the currently installed plg to determine if update is available. The downloaded plg file is left in /tmp.

 

2. to update, plgMan invokes 'plugin update <name.plg>" - this "installs" the new plg file located in /tmp.  If install is successful, the old plg file is moved from /boot/config/plugins to /boot/config/plugins-stale, and the new plg file is moved from /tmp to /boot/config/plugins.

 

So 'stale' plugins is really just a list of plg files present in /boot/config/plugins-stale.  Probably the stale-plugins directory is not needed and plgMan should just delete the old plg file when a new plg is installed - was trying to avoid deleting stuff which user might want to restore, but realistically probably more trouble than it's worth.

Link to comment

I have converted a few plgs to the number 2 method. I must say not having a 1000 line plus plg is nice. And it was really easy once you do it once.

 

I agree that it is cleaner and easier to maintain.  It's not a technical issue for me, it's a time investment when I have limited spare time.  Apcupsd and powerdown work well at this time.

 

If this functionality is to eventually be in the unRAID core, it doesn't seem worth the effort to do a re-write at this time.

Link to comment

I'm changing the apcupsd plugin to not be dependent on the powerdown plugin.  Apcupsd will use the built in powerdown that works for an unRAID system with basic plugins and dockers.  Because of the move to dockers, there is less need for the powerdown plugin.  Shutting down docker stops all dockers properly.

 

The unRAID powerdown does a shutdown using the webgui and it operates the same as clicking on shutdown in the webgui.  It stops VMs and docker and is the appropriate shutdown mechanism.

 

Powerdown helps those with more complex systems that need help shutting down, for those needing custom start and stop scripts, or for those that want historical logs kept on file from each shutdown.

Link to comment
  • 2 weeks later...

I have converted a few plgs to the number 2 method. I must say not having a 1000 line plus plg is nice. And it was really easy once you do it once. One thing I haven't had time to look at is after an update a stale is created. And maybe that is cause it's geared towards built-ins.

 

Done for Apcupsd.

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.