question about shutdown and queue

Get help with all aspects of SABnzbd
Forum rules
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.
Post Reply
bobbintb
Newbie
Newbie
Posts: 16
Joined: August 24th, 2012, 11:09 am

question about shutdown and queue

Post 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?
User avatar
shypike
Administrator
Administrator
Posts: 19774
Joined: January 18th, 2008, 12:49 pm

Re: question about shutdown and queue

Post 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
bobbintb
Newbie
Newbie
Posts: 16
Joined: August 24th, 2012, 11:09 am

Re: question about shutdown and queue

Post 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.
User avatar
sander
Release Testers
Release Testers
Posts: 9062
Joined: January 22nd, 2008, 2:22 pm

Re: question about shutdown and queue

Post 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.
bobbintb
Newbie
Newbie
Posts: 16
Joined: August 24th, 2012, 11:09 am

Re: question about shutdown and queue

Post 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.
User avatar
sander
Release Testers
Release Testers
Posts: 9062
Joined: January 22nd, 2008, 2:22 pm

Re: question about shutdown and queue

Post 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?
bobbintb
Newbie
Newbie
Posts: 16
Joined: August 24th, 2012, 11:09 am

Re: question about shutdown and queue

Post 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.
premiso
Release Testers
Release Testers
Posts: 16
Joined: June 28th, 2010, 11:43 am

Re: question about shutdown and queue

Post 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.
Post Reply