Page 1 of 1
Trouble using scripts on Qnap NAS
Posted: March 18th, 2019, 1:51 am
by kallek
I'm having trouble executing my script on a Qnap NAS. I have a simple script that turns off the NAS that looks like this:
It is made executable with +x and I select that it should run at the end of the queue, but nothing happens. I can run the script if I ssh and type "bash shutdown.sh".
What am I doing wrong?
Re: Trouble using scripts on Qnap NAS
Posted: March 18th, 2019, 2:11 am
by OneCD
Have you tried the "Shutdown PC" action?
Re: Trouble using scripts on Qnap NAS
Posted: March 18th, 2019, 7:15 am
by kallek
OneCD wrote: ↑March 18th, 2019, 2:11 am
Have you tried the "Shutdown PC" action?
It's not available on a NAS
Re: Trouble using scripts on Qnap NAS
Posted: March 18th, 2019, 2:17 pm
by OneCD
Okiedoke, just had a look at the SAB code.
These snippets are from [sabnzbd/powersup.py]:
Code: Select all
try:
import dbus
HAVE_DBUS = True
except ImportError:
HAVE_DBUS = False
Code: Select all
def linux_shutdown():
""" Make Linux system shutdown, never returns """
if not HAVE_DBUS:
os._exit(0)
QTS doesn't use DBUS, so SAB is unable to offer power options.
In that case, your shutdown script seems like the right way to go.
I'll do some testing and see if I can get shutdown working via your script.
Re: Trouble using scripts on Qnap NAS
Posted: March 18th, 2019, 3:50 pm
by sander
kallek wrote: ↑March 18th, 2019, 1:51 am
I'm having trouble executing my script on a Qnap NAS. I have a simple script that turns off the NAS that looks like this:
It is made executable with +x and I select that it should run at the end of the queue, but nothing happens. I can run the script if I ssh and type "bash shutdown.sh".
What am I doing wrong?
Maybe SABnzbd is running as a user with other, less rights? Maybe n o rights to run the script and/or to run /sbin/poweroff ?
BTW Because of the shebang, no need to say "bash <blabla>"
Re: Trouble using scripts on Qnap NAS
Posted: March 18th, 2019, 4:51 pm
by OneCD
I created a new script called [testoff.sh] and placed it into my scripts directory. This is on a TS-559 Pro+ running QTS 4.2.6 #20181227.
This script contains:
Made it executable:
Then selected this script to be run when queue completes.
Works fine. When the last queue item completed, the NAS powered-off.
Re: Trouble using scripts on Qnap NAS
Posted: March 18th, 2019, 5:01 pm
by OneCD
sander wrote: ↑March 18th, 2019, 3:50 pm
Maybe SABnzbd is running as a user with other, less rights? Maybe n o rights to run the script and/or to run /sbin/poweroff ?
In QTS, almost all apps run with $EUID = 0. It's not ideal.
Re: Trouble using scripts on Qnap NAS
Posted: March 19th, 2019, 1:43 am
by kallek
OneCD wrote: ↑March 18th, 2019, 5:01 pm
sander wrote: ↑March 18th, 2019, 3:50 pm
Maybe SABnzbd is running as a user with other, less rights? Maybe n o rights to run the script and/or to run /sbin/poweroff ?
In QTS, almost all apps run with $EUID = 0. It's not ideal.
It looks as if Sabnzbd is running as user admin. I have disabled the admin user in QTS, but I guess Sabnzbd is able to use it anyway. Is there a way of running Sabnzbd as a less privileged user? It's a little scary if someone manage to hack the web login and get admin access.
I will try your new script when I get home.
Re: Trouble using scripts on Qnap NAS
Posted: March 19th, 2019, 2:21 am
by OneCD
kallek wrote: ↑March 19th, 2019, 1:43 am
I have disabled the admin user in QTS...
That's not a good idea. Your NAS is no better secured and it creates other issues, particularly when you’re trying to fix things.
How did you install SABnzbd? Sherpa script?
kallek wrote: ↑March 19th, 2019, 1:43 am
Is there a way of running Sabnzbd as a less privileged user?
For now, I'm only able to support running SABnzbd as 'admin' on QTS.
kallek wrote: ↑March 19th, 2019, 1:43 am
It's a little scary if someone manage to hack the web login and get admin access.
Don't expose any services running on your QNAP to the Internet. Either use a reverse-proxy or VPN into your LAN.
Re: Trouble using scripts on Qnap NAS
Posted: March 20th, 2019, 1:47 am
by kallek
OneCD wrote: ↑March 19th, 2019, 2:21 am
How did you install SABnzbd? Sherpa script?
Yes, I used the Sherpa script.
OneCD wrote: ↑March 19th, 2019, 2:21 am
Don't expose any services running on your QNAP to the Internet. Either use a reverse-proxy or VPN into your LAN.
Ok, So I setup a VPN on my router. Only thing I haven't got to work is Wake On LAN, so I still have to expose a UDP port. I don't know if that is such a security concern though.
I tried your script but I still can't run it from Sabnzbd. I select it to run at the end of the queue and the icon turns red. When the queue is finished nothing happens and the icon remains red and the script is still selected. If I ssh into the nas and run the script with bash shutdown.sh it works. I also enabled the admin user, but it didn't make a difference.
Permissions of the file are:
Code: Select all
-rwxrwxrwx 1 kalle everyone 31 2019-03-19 07:49 shutdown.sh*
Is there a log file in sabnzbd that could tell me what is happening? I tried viewing the sabnzbd error log file, but it is over 500 MB and doesn't seem to be in text format.
Re: Trouble using scripts on Qnap NAS
Posted: March 20th, 2019, 2:02 am
by OneCD
kallek wrote: ↑March 20th, 2019, 1:47 am
Yes, I used the Sherpa script.
Excellent.
OneCD wrote: ↑March 19th, 2019, 2:21 am
If I ssh into the nas and run the script with bash shutdown.sh it works.
As @sander mentioned above, you don't need to type:
... if the script is executable and has a hashbang line.
Assuming you’re already in the directory containing the script, use this:
Your [shutdown.sh] script should be in [/share/Download/nzbToMedia/], correct?
Please SSH into your NAS as the 'admin' user, then run this:
Code: Select all
cat -A /share/Download/nzbToMedia/shutdown.sh
... then copypaste the result back here from your terminal window.
kallek wrote: ↑March 20th, 2019, 1:47 am
Is there a log file in sabnzbd that could tell me what is happening? I tried viewing the sabnzbd error log file, but it is over 500 MB and doesn't seem to be in text format.
I'll let the SAB experts answer that one. But 500MB seems a little large.
Re: Trouble using scripts on Qnap NAS
Posted: March 21st, 2019, 1:35 am
by kallek
OneCD wrote: ↑March 19th, 2019, 2:21 am
Your [shutdown.sh] script should be in [/share/Download/nzbToMedia/], correct?
I had made a new folder in [share/Download/Scripts] and pointed sabnzbd to use that folder. When I moved my script to [/share/Download/nzbToMedia/] it works! I can now execute the script from sabnzbd upon queue completion.
Thanks for all the help!
Re: Trouble using scripts on Qnap NAS
Posted: March 21st, 2019, 1:43 am
by OneCD
Nicely done.