Jump to content
Automatic

Run/Stop an executable upon taking the array online/offline?

10 posts in this topic Last Reply

Recommended Posts

Sabnzbd seems to stop my array from shutting down (It just idles on 'syncing filesystems'), if I were to throw together a quick python script to connect to the shutdown page (localhost:8081/shutdown?session=blah) how would I get it execute upon taking the array offline?

Share this post


Link to post

unRAID 5.X will look in "event-named" directories under /usr/local/emhttp/plugins/ for an executable script in a "plugin-name/event" directory and invoke it as it stops services prior to un-mounting the disks on array stop

/usr/local/emhttp/plugins/sanzbd/event/stopping_svcs

 

You can put something like this in your "config/go" script to move a copy of your script to that location each time you reboot.

mkdir -p /usr/local/emhttp/plugins/sanzbd/event/

cp /boot/sabnzbd_shutdown /usr/local/emhttp/plugins/sanzbd/event/stopping_svcs

chmod +x /usr/local/emhttp/plugins/sanzbd/event/stopping_svcs

 

The actual plugin name (shown in blue above) does not matter other than do not use directory names with spaces.  You do not need to have a plugin with that name, but it is where the event system looks.

You can put event related files there as needed.  They are invoked in lexical order..  As an example, if you had

/usr/local/emhttp/plugins/sanzbd/event/stopping_svcs

/usr/local/emhttp/plugins/01_joe/event/stopping_svcs

/usr/local/emhttp/plugins/02_joe/event/stopping_svcs

01_joe would invoke first, 02_joe second, and sanzbd third.

 

The actual /boot/sabnzbd_shutdown file would then have as its contents:

wget -O - localhost:8081/shutdown?session=blah

 

One warning.  If any "event" script fails to end, or waits for user input, the entire unRAID shutdown process will stop and wait forever to continue.

 

To see other potential events look in /usr/local/sbin/emhttp_event

 

Edit: fixed name of event from stopping_services to stopping_svcs in examples.

Share this post


Link to post

unRAID will look in "event-named" directories under /usr/local/emhttp/plugins/ for an executable script in a "plugin-name/event" directory and invoke it as it stops services prior to un-mounting the disks on array stop

/usr/local/emhttp/plugins/sanzbd/event/stopping_svcs

 

You can put something like this in your "config/go" script to move a copy of your script to that location each time you reboot.

mkdir -p /usr/local/emhttp/plugins/sanzbd/event/

cp /boot/sabnzbd_shutdown /usr/local/emhttp/plugins/sanzbd/event/stopping_svcs

chmod +x /usr/local/emhttp/plugins/sanzbd/event/stopping_svcs

 

The actual plugin name (shown in blue above) does not matter other than do not use directory names with spaces.  You do not need to have a plugin with that name, but it is where the event system looks.

You can put event related files there as needed.  They are invoked in lexical order..  As an example, if you had

/usr/local/emhttp/plugins/sanzbd/event/stopping_svcs

/usr/local/emhttp/plugins/01_joe/event/stopping_svcs

/usr/local/emhttp/plugins/02_joe/event/stopping_svcs

01_joe would invoke first, 02_joe second, and sanzbd third.

 

The actual /boot/sabnzbd_shutdown file would then have as its contents:

wget -O - localhost:8081/shutdown?session=blah

 

One warning.  If any "event" script fails to end, or waits for user input, the entire unRAID shutdown process will stop and wait forever to continue.

 

To see other potential events look in /usr/local/sbin/emhttp_event

 

Thanks for this post, exactly what I needed. Also, the reason why I can't use wget is because I've never done any sort of bash formatting (nor do I know any real built in linux commands) before and I need to first use a connection to grab the session from the index page. Something along the lines of:-

 

String sessionID = Regex(getPage("localhost:8081"), "var session = \"(.+?)\";", group.one);
getPage(String.format("localhost:8081/shutdown?session=%s", sessioNID));

 

Obviously the above isn't real code, but, it gets the point across.

 

Edit by Joe L. as moderator, to fix example event name to eliminate confusion

Share this post


Link to post

I'm having some problems with this.  I want to automatically stop MySQL from running when I stop the array.  The exerpt from my go file is:

 

mkdir -p /usr/local/emhttp/plugins/mysql/event/unmounting_disks/
cp /boot/mysqlstop /usr/local/emhttp/plugins/mysql/event/unmounting_disks
chmod +x /usr/local/emhttp/plugins/mysql/event/unmounting_disks/

 

my "mysqlstop" file is:

 

cd /
mysqladmin shutdown

 

I've installed MySQL without a password so that it shuts down without waiting for user input.  However, it doesn't appear that my script is ever run.  The script itself works fine, as I can execute it no problems from the console.

 

The syslog doesn't give any errors that I can find.  I have tried both stopping_svcs and unmounting_disks as events.

 

I'm running 5.0RC11, because 5.0 final locks up intermittently on my system because of one of the other plug-ins which I am running.  I haven't gotten around yet to isolating the plug in which is causing the issue, but it is MySQL which is preventing the disks from unmounting

 

 

Any help would be appreciated.

syslog-2013-09-28.txt

Share this post


Link to post

give the full path to mysqladmin.  When invoked by emhttp it might not know where it is located.

Share this post


Link to post

what I did was

 

make a stopping_svcs script with the line:

sh /etc/rc.d/rc.mysqld stop

 

needs the 'sh' because for some reason when installed rc.mysqld is not set with execute permission and this is a simple way around that.

 

 

So to get my stopping_svcs(and any other scripts I made) into the right folder I added the following lines to go script(/boot/config/go or from smb share /flash/config/go)

 

#Copy my scripts and set permissions

mkdir -p /usr/local/emhttp/plugins/myscript/event/

cp /boot/myscript/* /usr/local/emhttp/plugins/myscript/event/*

chmod +x /usr/local/emhttp/plugins/myscript/event/*

 

as im sure it will be useful to others I also made a 'started' script(which gets copied at same time with above commands) with the following lines to install mysql once the array is started

 

#install mysqld

sh /boot/packages/mysql-5.0.67-i486-1.tgz.manual_install

 

if mysqld is already installed then the above script will only restart it(which is what we want)

 

mysql must be installed from unMenu the first time so that all the variables in the install script are correct

Share this post


Link to post

what I did was

 

make a stopping_svcs script with the line:

sh /etc/rc.d/rc.mysqld stop

 

needs the 'sh' because for some reason when installed rc.mysqld is not set with execute permission and this is a simple way around that.

 

 

So to get my stopping_svcs(and any other scripts I made) into the right folder I added the following lines to go script(/boot/config/go or from smb share /flash/config/go)

 

#Copy my scripts and set permissions

mkdir -p /usr/local/emhttp/plugins/myscript/event/

cp /boot/myscript/* /usr/local/emhttp/plugins/myscript/event/*

chmod +x /usr/local/emhttp/plugins/myscript/event/*

 

as im sure it will be useful to others I also made a 'started' script(which gets copied at same time with above commands) with the following lines to install mysql once the array is started

 

#install mysqld

sh /boot/packages/mysql-5.0.67-i486-1.tgz.manual_install

 

if mysqld is already installed then the above script will only restart it(which is what we want)

 

mysql must be installed from unMenu the first time so that all the variables in the install script are correct

 

There is a new version of powerdown that can help with the start and stop process.  Powerdown is installed by Dynamix, and the apcupsd plugin.  The apcupsd plugin for V6 has not been updated yet, but it's a simple matter to change the one you have to install the latest powerdown package.  You can also install powerdown as a stand alone plugin.

 

This post http://lime-technology.com/forum/index.php?topic=31735.0 describes how it works.

Share this post


Link to post

Is the information in this thread still valid for the latest unRAID 6.x builds?

 

I have a script I want to run once the array is started and this seems like the right way to do it rather than implicitly calling it from the 'go' script.

 

Share this post


Link to post

Is the information in this thread still valid for the latest unRAID 6.x builds?

 

I have a script I want to run once the array is started and this seems like the right way to do it rather than implicitly calling it from the 'go' script.

Either that or you can use the user scripts plugin

 

Sent from my LG-D852 using Tapatalk

 

 

Share this post


Link to post

Personally I’d use the User.Scripts Plugin. You can use the option for when array starts or when stray stops. 

 

For instsnce I have one that creates a text file of all my drives every time I stop my array. Just Incase I do something stupid I can refer to what my drive assignments are. Lol 

Share this post


Link to post

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.