[SCRIPT] create-autorun.sh

Introduce yourself to us and other members here, or share your own product reviews, suggestions, and tips and tricks of using QNAP products.
Post Reply
ogio855
New here
Posts: 7
Joined: Thu Nov 27, 2014 2:06 am

Re: [SCRIPT] autorun.sh installer

Post by ogio855 »

Thanks for the reply, turns out I was missing a / before the destination, it would run, no errors and then just wouldn't copy. Or if it was copying who knows where it went!
somy1982
Easy as a breeze
Posts: 372
Joined: Fri Apr 08, 2016 6:42 pm

Re: [SCRIPT] autorun.sh installer

Post by somy1982 »

Hi, just to double check, does this run the scripts after resuming from sleep? Thanks!
User avatar
OneCD
Guru
Posts: 12155
Joined: Sun Aug 21, 2016 10:48 am
Location: "... there, behind that sofa!"

Re: [SCRIPT] autorun.sh installer

Post by OneCD »

Hmm, good question! I don't think so, but I've never used sleep mode. ;)

ImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImage
somy1982
Easy as a breeze
Posts: 372
Joined: Fri Apr 08, 2016 6:42 pm

Re: [SCRIPT] autorun.sh installer

Post by somy1982 »

Would be nice to auto run some script also when shutdown :-)
User avatar
OneCD
Guru
Posts: 12155
Joined: Sun Aug 21, 2016 10:48 am
Location: "... there, behind that sofa!"

Re: [SCRIPT] autorun.sh installer

Post by OneCD »

Well, you could always hook into /etc/init.d/poweroff

You'd need to place your hook after every boot though. ;)

ImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImage
seppi0815
New here
Posts: 5
Joined: Thu Nov 24, 2011 4:49 pm

Re: [SCRIPT] autorun.sh installer

Post by seppi0815 »

Hi OneCD,

thank you very much for your create-autorun script. It works very fine.

But I have troubles starting nzbget V19 as a service while system startup (nzbget -D).
The autorun.log shows me the start of 010-script.sh.
Everything seems to be fine but nzbget doesn't start.

When I start autorun.sh manually nzbget will be started.

Any ideas?
Thanks in advance.

010-script.sh...
/opt/bin/nzbget/nzbget -D

autorun.log...
Mon Apr 24 20:00:04 CEST 2017 ----- running autorun.sh -----
Mon Apr 24 20:00:04 CEST 2017 - /share/HDA_DATA/.system/autorun/scripts/010-script.sh
User avatar
OneCD
Guru
Posts: 12155
Joined: Sun Aug 21, 2016 10:48 am
Location: "... there, behind that sofa!"

Re: [SCRIPT] autorun.sh installer

Post by OneCD »

Hi and welcome to the forum. :)
seppi0815 wrote:But I have troubles starting nzbget V19 as a service while system startup (nzbget -D).
The autorun.log shows me the start of 010-script.sh.
Everything seems to be fine but nzbget doesn't start.

When I start autorun.sh manually nzbget will be started.
Looks like you're using NZBGet installed through Entware. If so, Entware may not have been init before your script is run. You may need to introduce a wait so that Entware has time to load during NAS boot, and NZBGet becomes available. I already have a wait script to do this for SABnzbd. Please advise if you'd like to use this method.

Or, you could install the NZBGet QPKG so you won't need a script to start NZBGet daemonized. But this method requires even more work to get it running after boot. :roll:

ImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImage
seppi0815
New here
Posts: 5
Joined: Thu Nov 24, 2011 4:49 pm

Re: [SCRIPT] autorun.sh installer

Post by seppi0815 »

I did it this way :?
User avatar
OneCD
Guru
Posts: 12155
Joined: Sun Aug 21, 2016 10:48 am
Location: "... there, behind that sofa!"

Re: [SCRIPT] autorun.sh installer

Post by OneCD »

Oh, I see. :)

Are you using Entware or Optware? I ask because your NZBGet path is in /opt/bin

ImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImage
seppi0815
New here
Posts: 5
Joined: Thu Nov 24, 2011 4:49 pm

Re: [SCRIPT] autorun.sh installer

Post by seppi0815 »

I use Optware.
User avatar
OneCD
Guru
Posts: 12155
Joined: Sun Aug 21, 2016 10:48 am
Location: "... there, behind that sofa!"

Re: [SCRIPT] autorun.sh installer

Post by OneCD »

Maybe you could try this:

Code: Select all

#!/bin/sh

[ ! -z "$1" ] && timeout="$1" || timeout=600
[ ! -z "$2" ] && testfile="$2" || testfile="/opt/bin/nzbget/nzbget"
scriptname="$(/usr/bin/basename $0)"
waitlog="/var/log/wait-counter-${scriptname}.log"

if [ ! -e "$testfile" ]; then
	(
		for ((count=1; count<=timeout; count++)); do
			sleep 1
			[ -e "$testfile" ] &&
				{
				echo "waited for $count seconds" >> "$waitlog"
				true
				exit
				}
		done
		false
	)

	if [ "$?" -ne "0" ]; then
		echo "timeout exceeded!" >> "$waitlog"
		/sbin/write_log "[$scriptname] Could not continue: timeout exceeded." 1
		false
	else
		# if here, then testfile has appeared, so reload environment
		. /etc/profile
		. /root/.profile

		# finally, launch NZBGet
		/opt/bin/nzbget/nzbget -D
	fi
fi
Edit your existing launcher (010-script.sh), and replace the contents with those shown above.

This will wait for up to 10 minutes for /opt/bin/nzbget/nzbget to appear when run.

ImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImage
seppi0815
New here
Posts: 5
Joined: Thu Nov 24, 2011 4:49 pm

Re: [SCRIPT] autorun.sh installer

Post by seppi0815 »

Thanks for your reply.
While reboot "autorun.log" is written and 10 min later "wait...log" is created... timeout exceeded :roll:

Is it better to reinstall nzbget via optware?
User avatar
OneCD
Guru
Posts: 12155
Joined: Sun Aug 21, 2016 10:48 am
Location: "... there, behind that sofa!"

Re: [SCRIPT] autorun.sh installer

Post by OneCD »

I don't know if NZBGet is available through Optware. Optware is deprecated.

Try Entware instead. NZBGet is available as an installable IPK. ;)

Code: Select all

opkg install nzbget

ImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImage
seppi0815
New here
Posts: 5
Joined: Thu Nov 24, 2011 4:49 pm

Re: [SCRIPT] autorun.sh installer

Post by seppi0815 »

Thank you for the "Entware" hint.
I didn't know about the end of Optware :oops:

I removed it, installed Entware and nzbget.
It works fine and starts actually without autorun scripts.

Thanks again for you help.
archimed7592
New here
Posts: 2
Joined: Mon Dec 08, 2014 2:36 am

Re: [SCRIPT] autorun.sh installer

Post by archimed7592 »

There is an order if QNAP initialization, it looks somewhat like this:
  1. ...
  2. LCD shows Starting Service Please wait
  3. ...
  4. autorun.sh
  5. ...
  6. Optware initialization
  7. ...
  8. QNAP beeps, initialization is complete
So, no matter how long you will wait for Optware component at step4 - it'll never appear. If you wait for Optware at step4 for 5 minutes, LCD will show "Starting Service Please wait" for 5 minutes longer...
You have to run autorun.sh in background. I ended up with these scripts:
/share/MD0_DATA/.system/autorun/autorun.sh

Code: Select all

#!/bin/bash

AUTORUN_PATH="/share/MD0_DATA/.system/autorun"
SCRIPT_STORE_PATH="/share/MD0_DATA/.system/autorun/scripts"
LOGFILE="/var/log/autorun.log"

echo "$(date) ----- running autorun.sh -----" >> "$LOGFILE"

"$AUTORUN_PATH/autorun2.sh" 2>&1 >> "$LOGFILE" &

echo "$(date) ----- finished autorun.sh -----" >> "$LOGFILE"

/share/MD0_DATA/.system/autorun/autorun2.sh

Code: Select all

#!/bin/bash

AUTORUN_PATH="/share/MD0_DATA/.system/autorun"
SCRIPT_STORE_PATH="/share/MD0_DATA/.system/autorun/scripts"
LOGFILE="/var/log/autorun.log"

echo "$(date) ----- running autorun2.sh -----" >> "$LOGFILE"

for i in ${SCRIPT_STORE_PATH}/* ; do
	if [[ -x $i ]] ; then
		echo -n "$(date)" >> "$LOGFILE"
		echo " - $i " >> "$LOGFILE"
		$i 2>&1 >> "$LOGFILE"
	fi
done

echo "$(date) ----- finished autorun2.sh -----" >> "$LOGFILE"
Post Reply

Return to “Users' Corner”