Skip to content
View in the app

A better way to browse. Learn more.

Unraid

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Controlling Plugin Start sequence

Featured Replies

Hi

I would like to run SNAP or otherwise mount a disk before any plugins start.

This disk would be used to hold the data files for the plugins.

 

I've tried doing this with SNAP plugin,  but there is a race condition.  Some of the other plugins start before SNAP and it gets wonky.

 

One thought is to hold my plugins outside the normal plugins directory and manually start them via the 'go' file, but I'm not sure how feasible this is.

Appreciate any other ideas.

Thanks in advance.

This sounds like a very reasonable request... You could try and make a feature request for the plugin manager.. Some way to establish an order in startup..

  • Author

How is it controlled now?

There must be some order ...  Alphabetic .. .. or top of 'ls -l' 

When you hook up a monitor and look ar startup you see they are serial, not parallel, no idea what defines the sequence..

Starting the plugins from the go file, specifying the order should get around the issue.  I agree that you should be able specify the start up order via the plugin manager.

I created my own plugin to solve the race condition, just saved it as "anetwait.plg" so its the first in the list to run - it simply forces the plugin loader to wait until there is a working Internet connection (it will time out eventually if there isnt so the system will still boot ok). I've sent it to Influencer in case he wants to publish it on his wiki, but you should be able to just copy it into a text editor and save it to your plugins folder:

 

<?xml version='1.0' standalone='yes'?>

 

<PLUGIN>

<!-- wait for Internet access -->

<FILE Name="/tmp/tomsinetwait" Run="/bin/bash">

<INLINE>

<![CDATA[

#!/bin/sh

x=`ping -c1 google.com 2>&1 | grep -i unknown`

COUNT=0

while [ $COUNT -lt 10 ]; do

        if [ ! "$x" = "" ]; then

        echo "Waiting for Internet access"

        sleep 10

        fi

        let COUNT=COUNT+1

       

done

rm /tmp/tomsinetwait

echo "tom script done"

]]>

</INLINE>

</FILE>

</PLUGIN>

I'll add this to my repo(with proper credits given of course) so its easier to find. This will come in handy! And again points to the issue I've been harping about all along, plug-ins need to wait to be installed until after the array comes online so that everything is running and stable to stop these sort of race conditions. Most plugins(atleast mine) do not initialize until the array is online, but they are still installed during boot, so anything that needs the network may try downloading before the network comes up.

  • Author

Thanks Guys

I created a feature req for this for the plugin mgr.

 

In my case .. i wasn't waiting for the array per se.. but I needed SNAP started 1st to mount a drive.

Haven't tested .. but I think I could have renamed the plugin to aaaaaaa_snapxx.plg to make it start 1st

 

 

Yep, I'd originally inserted that code into my couchpotato2.plg because the log showed it was the first to try and start, then I realised it must be processing them alphabetically so was just a case of making a standalone plugin top of the folder list :)

 

You can use the following as an if statement to check whether the array is online, but as Influencer says his plugins do that anyway - I don't know about the SNAP one so it might come in handy:

 

if [ ! -d /mnt/disk1 ]

    then

      sleep 15

    fi

 

 

 

Snap wouldn't need the array to come online to start, it would actually be preferable if SNAP DID come online first.

Ah, I should have found out a bit more about Snap before merrily posting away :)

Thank you so much, this completly fixes the issue I had with just having plugins install themselves.  Now I can remove all my wait and starts in my go file  :)

I created my own plugin to solve the race condition, just saved it as "anetwait.plg" so its the first in the list to run - it simply forces the plugin loader to wait until there is a working Internet connection (it will time out eventually if there isnt so the system will still boot ok). I've sent it to Influencer in case he wants to publish it on his wiki, but you should be able to just copy it into a text editor and save it to your plugins folder:

 

<?xml version='1.0' standalone='yes'?>

 

<PLUGIN>

<!-- wait for Internet access -->

<FILE Name="/tmp/tomsinetwait" Run="/bin/bash">

<INLINE>

<![CDATA[

#!/bin/sh

x=`ping -c1 google.com 2>&1 | grep -i unknown`

COUNT=0

while [ $COUNT -lt 10 ]; do

        if [ ! "$x" = "" ]; then

        echo "Waiting for Internet access"

        sleep 10

        fi

        let COUNT=COUNT+1

       

done

rm /tmp/tomsinetwait

echo "tom script done"

]]>

</INLINE>

</FILE>

</PLUGIN>

Unless I'm completely off-base, the "ping" of google.com is outside of the counting loop.  It may seem like the script is working, but only because eventually the count-down variable reaches 10 (after 100 seconds)  The way it is written, it is simply a 100 second delay if the initial ping fails.  You really want to continue as soon as the network is available.

 

The fix would be to put the ping of google.com INSIDE the loop, just prior to where it is being tested.  This way, the loop will continue as soon as the network ping is successful. 

 

I might suggest you consider an equivalent plugin to recognize when all the disks have been mounted and the array started.  Often disks are not mounted immediately after a forced shutdown.  They can take as long as 30 minutes of more to replay their journal transactions before they are available.

 

Joe L.

 

<?xml version='1.0' standalone='yes'?>

 

<PLUGIN>

<!-- wait for Internet access -->

<FILE Name="/tmp/tomsinetwait" Run="/bin/bash">

<INLINE>

<![CDATA[

#!/bin/sh

COUNT=0

while [ $COUNT -lt 10 ]; do

      x=`ping -c1 google.com 2>&1 | grep -i unknown`

        if [ ! "$x" = "" ]; then

        echo "Waiting for Internet access"

        sleep 10

        fi

        let COUNT=COUNT+1

     

done

rm /tmp/tomsinetwait

echo "tom script done"

]]>

</INLINE>

</FILE>

</PLUGIN>

 

 

 

Joe L.

Joe, your bash scripting-fu is miles above mine, but don't the single back quotes mean that x is assigned the command within and then during the while loop the value of x takes on the exit status from the ping command?

 

Joe, your bash scripting-fu is miles above mine, but don't the single back quotes mean that x is assigned the command within and then during the while loop the value of x takes on the exit status from the ping command?

 

I think the point is that while x will take on the results of the ping command withing the backquotes ... it will only do it once and not be refreshed inside the while loop.  Based on my understanding, and a bit of google-fu to refresh / validate my understanding, backquotes only execute the command inside, full stop.  There is no feature of it being refreshed from within a while loop unless the command itself is within that loop (as modified by Joe).

 

That said, $() is the "modern" way to do the same thing :)

... and that's why I love this stuff.  There's always something new to learn.  Figured I must be missing something. 

 

Thank you for clearing it up!

 

of course I'm bored and decided to refresh my memory a bit, I ran across this:

 

ping sun8 > /dev/null 2>&1
if [ $? -eq ]
then
echo "ping succeeded"
else
echo "ping failed"
fi

 

Not that it really matters in this case, but I like finding elegant solutions :)  In this case avoiding even defining x and assigning it a value.  I also like avoiding extra loops, no matter how quick, so I've added a break as soon as we get a good ping  So the whole code might look something like this (untested)

 

<?xml version='1.0' standalone='yes'?>

<PLUGIN>
<!-- wait for Internet access -->
<FILE Name="/tmp/tomsinetwait" Run="/bin/bash">
<INLINE>
<![CDATA[
#!/bin/sh
COUNT=0
while [ $COUNT -lt 10 ]; do
        ping -c1 google.com > /dev/null 2>&1
        if [ $? -eq ] 
        then
                break
        else 
                echo "Waiting for Internet access"
                sleep 10
        fi
        let COUNT=COUNT+1
done
rm /tmp/tomsinetwait
echo "tom script done"
]]>
</INLINE>
</FILE>
</PLUGIN>

that can be further condensed with


if ping -c3 localhost > /dev/null 2>&1
then echo "ping succeeded"
else echo "ping failed"
fi

 

 

any command on the if that returns 0 is a true and executes the then block

s'more food for thought.


#cat pingtest.sh 
#!/bin/bash


[ ${DEBUG:=0} -gt 0 ] && set -x -v


until ping -c3 localhostx > /dev/null 2>&1
do    (( LOOP=${LOOP:=0}+1 ))
      [ ${LOOP} -gt 10 ] && break
done


exit;


if ping -c3 localhost > /dev/null 2>&1
then echo "ping succeeded"
else echo "ping failed"
fi

 

And the associated Log, notice I'm using localhostX


root@atlas /tmp #DEBUG=3 ./pingtest.sh 


until ping -c3 localhostx > /dev/null 2>&1
do    (( LOOP=${LOOP:=0}+1 ))
      [ ${LOOP} -gt 10 ] && break
done
+ ping -c3 localhostx
+ ((  LOOP=0+1  ))
+ '[' 1 -gt 10 ']'
+ ping -c3 localhostx
+ ((  LOOP=1+1  ))
+ '[' 2 -gt 10 ']'
+ ping -c3 localhostx
+ ((  LOOP=2+1  ))
+ '[' 3 -gt 10 ']'
+ ping -c3 localhostx
+ ((  LOOP=3+1  ))
+ '[' 4 -gt 10 ']'
+ ping -c3 localhostx
+ ((  LOOP=4+1  ))
+ '[' 5 -gt 10 ']'
+ ping -c3 localhostx
+ ((  LOOP=5+1  ))
+ '[' 6 -gt 10 ']'
+ ping -c3 localhostx
+ ((  LOOP=6+1  ))
+ '[' 7 -gt 10 ']'
+ ping -c3 localhostx
+ ((  LOOP=7+1  ))
+ '[' 8 -gt 10 ']'
+ ping -c3 localhostx
+ ((  LOOP=8+1  ))
+ '[' 9 -gt 10 ']'
+ ping -c3 localhostx
+ ((  LOOP=9+1  ))
+ '[' 10 -gt 10 ']'
+ ping -c3 localhostx
+ ((  LOOP=10+1  ))
+ '[' 11 -gt 10 ']'
+ break


exit;
+ exit

Second run with successful localhost


root@atlas /tmp #DEBUG=3 ./pingtest.sh 


until ping -c3 localhost > /dev/null 2>&1
do    (( LOOP=${LOOP:=0}+1 ))
      [ ${LOOP} -gt 10 ] && break
done
+ ping -c3 localhost


exit;
+ exit

no one likes a show off ;-)

 

any command on the if that returns 0 is a true and executes the then block

 

I thought abuot that, but wasn't sure and can't test here at work.  Glad to see my instincts were right.  I am of course nothing more than a duffer here, but I can google the s#!t out of a topic :)

hmmm thinking ... and googling ... but isn't pinging localhost only going to tell you that the TCP/IP stack is up and running?  It won't actually tell you that you have been assigned an a network IP address, or that you have a valid connection to the outside world? 

 

That last bit might be nice when say ... first booting up "everything" after a long time away from home.  My cable modem, router, and unraid are all on the same ups.  When i go away for a long time, or when lightening is in the area, I shut everything down.  It would be nice to not have to manually wait for the modem and router to negotiate before powering up unraid.  That means validating a connection to the intertubes before continuing.

 

Or did I misread what pingning localhost actually tests?

You missed the point, I wasn't showing off, I was showing how you can code the if and loop small and concise.

I choose localhost and localhostx for a true and false condition showing how the loop reacts.

It was more of display of how bash can work to keep the number of lines to a minimum.

If I wanted to check my internet connectivity I might elect to ping the external address of my router or some other external address.

ISP's name servers, etc, etc.

 

 

ping also has the -i paramter to add a sleep between pings.

So ping -c2 -i10 might be effective.

haha sorry dude.  Joke was lost in text translation.  I was giving you credit for your skills which are far far above mine.

 

re: localhost ... ahhhh ok I gotcha.  I caught the implication of localhostX, but thought you were being literal about localhost.  My mistake.

 

And as always, thanks for all the effort you put in around here.

haha sorry dude.  Joke was lost in text translation.  I was giving you credit for your skills which are far far above mine.

 

re: localhost ... ahhhh ok I gotcha.  I caught the implication of localhostX, but thought you were being literal about localhost.  My mistake.

 

And as always, thanks for all the effort you put in around here.

 

I've learned allot of really cool bash and ksh techniques over the years.

Even writing cool bash C loadable plugins/functions.

I've been really excited about the new bash with associative arrays and co-processes too.  So any time I get to "show off" a neat technique I post it for others to learn from.

One of these days I'll post a sqlite and gdbm plugin for unRAID's bash so we can do DB type get/put of information.

I'm always looking for new techniques myself. OK back to plugin start sequence....

 

Since I haven't look at it in a long time. Does it process the plugins in name order?

Perhaps naming them a specific way would help control plugin sequence.

Yeah I was thinking about that ... seemed just give the plugins sequentially numbered names. 

 

1.waitfornetwork

2.waitforarray

98.sanzb

99.plex

Archived

This topic is now archived and is closed to further replies.

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.