Page 1 of 1
question about shutdown and queue
Posted: August 24th, 2012, 11:24 am
by bobbintb
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
Posted: August 24th, 2012, 11:44 am
by shypike
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
Re: question about shutdown and queue
Posted: August 24th, 2012, 12:06 pm
by bobbintb
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
Posted: August 24th, 2012, 1:16 pm
by sander
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.
Out of curiosity: on which platform are you? Linux, OSX, Windows, ... ?
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
Posted: August 24th, 2012, 2:41 pm
by bobbintb
sander wrote: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.
Out of curiosity: on which platform are you? Linux, OSX, Windows, ... ?
If you write in Python (just like SAB itself), you (and others) can run it anywhere. And I could help.
i am using linux (unraid to be specific). i actually whipped up something really quickly in python. never used it before.
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")
i do need help figuring something out though. i decided to modify my plan a little bit to make things less complicated (KISS). now what i am looking for is a way to also see if there are any items being processed after download. im looking at the advanced API output but am having trouble finding the right attribute. that and some of them in my actual output i can't find documentation for.
Re: question about shutdown and queue
Posted: August 24th, 2012, 3:19 pm
by sander
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?
Re: question about shutdown and queue
Posted: August 24th, 2012, 4:20 pm
by bobbintb
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.
Re: question about shutdown and queue
Posted: November 12th, 2013, 2:45 pm
by premiso
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.
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)
If you are still wanting this and mind testing, would be coooool.