question about shutdown and queue
Forum rules
Help us help you:
Help us help you:
- Are you using the latest stable version of SABnzbd? Downloads page.
- Tell us what system you run SABnzbd on.
- Adhere to the forum rules.
- Do you experience problems during downloading?
Check your connection in Status and Interface settings window.
Use Test Server in Config > Servers.
We will probably ask you to do a test using only basic settings. - Do you experience problems during repair or unpacking?
Enable +Debug logging in the Status and Interface settings window and share the relevant parts of the log here using [ code ] sections.
question about shutdown and queue
this may sound like an odd request but i am trying to set some automation set up and have a question. right now i am setting up my server dev system to automatically start up at a certain time of day, sabnzb will process the queue and shutdown when done. then the server will check if sabnzbd is running and if not, shut itself down. now there will inevitably be times when there is nothing in the queue to begin with. sabnzbd is set to shut itself down when the queue is empty but obviously there is protection so that if the queue is empty as soon as the program starts, it doesnt do that. a program that shuts itself down immediately after starting is usually a bad idea. the issue is that i need it to do that, with a time delay obviously. is there any way to setup sabnzbd so that when it starts up with an empty queue and the queue is still empty after, say, five minutes, it then shuts itself down?
Re: question about shutdown and queue
What you ask is not possible.
However, SABnzbd does have an API and writing a simple script shouldn't be very hard to do.
A few "curl" calls will do.
The API is described here: http://wiki.sabnzbd.org/api
However, SABnzbd does have an API and writing a simple script shouldn't be very hard to do.
A few "curl" calls will do.
The API is described here: http://wiki.sabnzbd.org/api
Re: question about shutdown and queue
thanks for the help. i didnt think it would be. but that did give me a direction. i think i'll just try and write a script to check if the queue is empty and shutdown if it is. thanks again.
Re: question about shutdown and queue
Out of curiosity: on which platform are you? Linux, OSX, Windows, ... ?bobbintb wrote:thanks for the help. i didnt think it would be. but that did give me a direction. i think i'll just try and write a script to check if the queue is empty and shutdown if it is. thanks again.
If you write in Python (just like SAB itself), you (and others) can run it anywhere. And I could help.
Re: question about shutdown and queue
i am using linux (unraid to be specific). i actually whipped up something really quickly in python. never used it before.sander wrote:Out of curiosity: on which platform are you? Linux, OSX, Windows, ... ?bobbintb wrote:thanks for the help. i didnt think it would be. but that did give me a direction. i think i'll just try and write a script to check if the queue is empty and shutdown if it is. thanks again.
If you write in Python (just like SAB itself), you (and others) can run it anywhere. And I could help.
Code: Select all
#!/usr/bin/python
#import library to do http requests:
import urllib2
import os
#import easy to use xml parser called minidom:
from xml.dom.minidom import parseString
#download the file:
file = urllib2.urlopen('http://192.168.68.138:8081/sabnzbd/api?
mode=qstatus&output=xml&apikey=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX')
#convert to string:
data = file.read()
file.close()
#parse the xml you downloaded
dom = parseString(data)
xmlTag = dom.getElementsByTagName('noofslots')[0].toxml()
xmlData=xmlTag.replace('<noofslots>','').replace('</noofslots>','')
#shutdown if queue empty
if xmlData == "0":
print "No items in SABnzbd queue. Shutting down."
os.system ("/etc/rc.d/rc.sabnzbd stop")
Re: question about shutdown and queue
That looks impressive.
Do you mean you want to be sure things have been fully repaired and unpacked? Can't you check the History for that? I my current status I see "Status: Completed". So I guess the Status: can also be something like Repairing?
Do you mean you want to be sure things have been fully repaired and unpacked? Can't you check the History for that? I my current status I see "Status: Completed". So I guess the Status: can also be something like Repairing?
Re: question about shutdown and queue
yea, most of that code was courtesy of google. but yes, i dont want it to shut down if it is in the middle of unpacking, repairing, or even running a post-processing script. maybe "status" is the one i'm looking for. i'll do some testing and see what i get.
no, that wont work because it says "idle" both when it is unpacking and when it is doing nothing. is there an attribute for "jobs"? something that tells me it has items to process whether it be the queue, unpacking, repairing, post-process scripts, etc.
no, that wont work because it says "idle" both when it is unpacking and when it is doing nothing. is there an attribute for "jobs"? something that tells me it has items to process whether it be the queue, unpacking, repairing, post-process scripts, etc.
Re: question about shutdown and queue
I like the necro necro NECRO!
Well a mib came into IRC asking the same question. I took your script and added a sleep timer to it before calling the shutdown. I do not know if this will lockup the process so it does not repair etc, but yea.
If you are still wanting this and mind testing, would be coooool.
Well a mib came into IRC asking the same question. I took your script and added a sleep timer to it before calling the shutdown. I do not know if this will lockup the process so it does not repair etc, but yea.
Code: Select all
#!/usr/bin/python
#import library to do http requests:
import urllib2
import time
#import easy to use xml parser called minidom:
from xml.dom.minidom import parseString
#CHANGE THE BELOW!
# Change these items to match your setup.
scheme = 'http' # change to https if using that.
host = "sab.ip.add.ress" # EG 127.0.0.1
port = "yourport" # EG 8080
apikey = "yoursabapikey" # EG ...a lot of shit
#download the file:
file = urllib2.urlopen(scheme '://' host ':' port '/sabnzbd/api?mode=qstatus&output=xml&apikey=' apikey)
#convert to string:
data = file.read()
file.close()
#parse the xml you downloaded
dom = parseString(data)
xmlTag = dom.getElementsByTagName('noofslots')[0].toxml()
xmlData=xmlTag.replace('<noofslots>','').replace('</noofslots>','')
#shutdown if queue empty
if xmlData == "0":
print "No items in SABnzbd queue. Shutting down."
time.sleep(500) # sleep for 500seconds so sab can finish
urllib2.urlopen(scheme '://' host ':' port '/sabnzbd/api?mode=shutdown&apikey=' apikey)