Created attachment 357960 [details] New sabnzbd init script Since the init script included with net-nntp/sabnzbd-0.7.14 has issues I decided to re-write it. This version (attached) includes: + Fixed issue with PIDfile being read before it is created (See https://bugs.gentoo.org/show_bug.cgi?id=483374) + Fixed issue with shutdown sequence on HTTPS. The script can now gracefully shutdown SABnzbd whether running in HTTP or HTTPS mode. + Improved the configfile parsing efficiency by reducing five commands down to one line of sed. + Made various improvements to code efficiency and readability by reducing overall code to a bare minium and removing unecessary loops. I've tested this script on my system in configurations of HTTP and HTTPS as well as testing various corner cases such as if we try to gracefully shutdown when the process has already died. I can attach formal logs if required.
Created attachment 357962 [details, diff] New sabnzbd init script (diff against exiting init script in 0.7.14)
I've marked this as "High" "Enhancement" subject to review. I'd like to mark this bug "As a Fix For" B-483374 but can't find where I can set up a relationship like that. The Bug Database I use at work is very different to Bugzilla. :)
Title changed to be somewhat less presumptious - though I'm fairly sure this init script is working after my rigorous testing.
Does not work at all for me. When I run the patched sabnzbd service, a fresh sabnzbd environment is created into /var/lib/sabnzbd/.sabnzbd, the daemon is running, but I lost all database informations (which sould be read from /var/lib/sabnzbd/admin), and the web browser links is also running, probably on the sabnzbd setup page.
Hi, Thanks for taking some time to test this. Can you please attach a full log as well as information regarding the environment you have and I'll take a look.
Created attachment 358016 [details] sabnzbd.log Here is the log file created into /var/lib/sabnzbd/.sabnzbd/logs when I start the patched service. Sabnzbd is running : > # ps aux | grep sabnzbd > sabnzbd 7665 0.0 0.0 13832 1596 ? Ss 10:54 0:00 /bin/sh /usr/bin/sabnzbd 563.pid --config-file /etc/sabnzbd/sabnzbd.ini --logging 1 --daemon --pid /var/run/sabnzbd > sabnzbd 7670 0.4 1.5 1790692 61488 ? Sl 10:54 0:01 /usr/bin/python2.7 SABnzbd.py 563.pid --config-file /etc/sabnzbd/sabnzbd.ini --logging 1 --daemon --pid /var/run/sabnzbd But the service fails stopping it : > # /etc/init.d/sabnzbd stop > * Stopping SABnzbd ... > * Attempting web-based shutdown @ http://localhost news.eu.supernews.com:8080 563 > * Falling back to SIGTERM, this may not work if you restarted via the web interface > * start-stop-daemon: fopen `/var/run/sabnzbd/sabnzbd-8080': No such file or directory [ ok ] Configuration file : > # ls -l /etc/sabnzbd/ > -rw------- 1 sabnzbd sabnzbd 3737 6 sept. 10:09 sabnzbd.ini > -rw-r--r-- 1 sabnzbd sabnzbd 3737 6 sept. 10:09 sabnzbd.ini.bak Hidden links and sabnzbd directories are created ing /var/lib/sabnzbd : > # ls -la /var/lib/sabnzbd/ > drwxr-xr-x 7 sabnzbd root 4096 6 sept. 10:54 . > drwxr-xr-x 30 root root 4096 6 sept. 09:59 .. > drwx------ 2 sabnzbd sabnzbd 4096 6 sept. 10:54 .links > drwxr-xr-x 4 sabnzbd sabnzbd 4096 6 sept. 10:54 .sabnzbd > drwxr-xr-x 3 sabnzbd sabnzbd 4096 6 sept. 09:32 Downloads > drwxr-xr-x 2 sabnzbd sabnzbd 4096 6 sept. 10:10 admin > drwxrwxr-x 2 sabnzbd sabnzbd 4096 1 sept. 11:48 dirscan
Ahh, there is the issue: > * Attempting web-based shutdown @ http://localhost news.eu.supernews.com:8080 563 The sed parsing may need tweaking as it is pulling out the address of one of your news servers as well as the host sabnzbd is running on. It also is affecting the pid line. I'll take a look at this when I get in tonight. Can you please attach your sabnzbd.ini? Thanks!
Created attachment 358020 [details] sanitized sabnzbd.ini
Created attachment 358152 [details] New sabnzbd init script + Fixed the sed line to limit the range of substitution
Created attachment 358154 [details, diff] New sabnzbd init script (diff against existing init script in 0.7.14) + Fixed the sed line to limit the range of substitution
(In reply to Fab from comment #8) > Created attachment 358020 [details] > sanitized sabnzbd.ini Hi Fab, Can you test the updated script? Thanks!
It starts and runs fine, but fails to stop it. > * Falling back to SIGTERM, this may not work if you restarted via the web interface > .pid': No such file or directory In the stop() function, when I do : > echo ${addr} > echo ${pidfile} It outputs : > :8080//localhost > .pid/run/sabnzbd/sabnzbd-8080
Created attachment 358276 [details] New sabnzbd init script + Fixed the sed line to limit the range of substitution + Added workaround for DOS line endings in sabznbd.ini (See: https://bugs.gentoo.org/show_bug.cgi?id=484236)
Created attachment 358278 [details, diff] New sabnzbd init script (diff against existing init script in 0.7.14) + Fixed the sed line to limit the range of substitution + Added workaround for DOS line endings in sabznbd.ini (See: https://bugs.gentoo.org/show_bug.cgi?id=484236)
Now it works fine. Thanks !
Created attachment 358284 [details] New sabnzbd init script + Fixed the sed line to limit the range of substitution + Added workaround for DOS line endings in sabznbd.ini (See: https://bugs.gentoo.org/show_bug.cgi?id=484236) + Made sed regexp more robust.
Created attachment 358286 [details, diff] New sabnzbd init script (diff against existing init script in 0.7.14) + Fixed the sed line to limit the range of substitution + Added workaround for DOS line endings in sabznbd.ini (See: https://bugs.gentoo.org/show_bug.cgi?id=484236) + Made sed regexp more robust.
(In reply to Fab from comment #15) > Now it works fine. Thanks ! Thanks for testing Fab. I've just attached (yet another :)) version. This version is much more robust as I've tweaked the ini parsing slightly. Let me know if you see any issues.
Created attachment 358294 [details] New sabnzbd init script + Fixed the sed line to limit the range of substitution + Added workaround for DOS line endings in sabznbd.ini (See: https://bugs.gentoo.org/show_bug.cgi?id=484236) + Made sed regexp more robust. + Even more robust as it is line ending agnostic! I could've cheated and used .* but I like to be explicit with what characters I'm actually consuming. :)
Created attachment 358296 [details, diff] New sabnzbd init script (diff against existing init script in 0.7.14) + Fixed the sed line to limit the range of substitution + Added workaround for DOS line endings in sabznbd.ini (See: https://bugs.gentoo.org/show_bug.cgi?id=484236) + Made sed regexp more robust. + Even more robust as it is line ending agnostic! I could've cheated and used .* but I like to be explicit with what characters I'm actually consuming. :)
If anyone is using the obsolted file(In reply to eponymous from comment #19) > Created attachment 358294 [details] > New sabnzbd init script > > + Fixed the sed line to limit the range of substitution > > + Added workaround for DOS line endings in sabznbd.ini (See: > https://bugs.gentoo.org/show_bug.cgi?id=484236) > > + Made sed regexp more robust. > > + Even more robust as it is line ending agnostic! I could've cheated and > used .* but I like to be explicit with what characters I'm actually > consuming. :) If anyone is using the older obsoleted files they should grab the newer version. Hopefully this will be included in the next ebuild of sabnzbd.
Created attachment 358602 [details] New sabnzbd init script + Added in graceful handling of race condition when restarting.
Created attachment 358604 [details, diff] New sabnzbd init script (diff against existing init script in 0.7.14) + Added in graceful handling of race condition when restarting.
+*sabnzbd-0.7.16 (08 Oct 2013) + + 08 Oct 2013; Justin Bronder <jsbronder@gentoo.org> -sabnzbd-0.7.13-r2.ebuild, + -sabnzbd-0.7.14.ebuild, +sabnzbd-0.7.16.ebuild, +files/par2cmdline.patch, + files/sabnzbd.initd, -files/sabnzbd.logrotate: + Version bump and remove old (#484226). Fix initd script thanks to eponymous + (#483786). Remove logrotate (#483672). Fix issues with stable version of + par2cmdline thanks to dcb (#480302). Note that I did make a few edits to your patch, but mainly expanding the one-line logic stuff for readability. Thanks again for all your work and testing!
(In reply to Justin Bronder from comment #24) > +*sabnzbd-0.7.16 (08 Oct 2013) > + > + 08 Oct 2013; Justin Bronder <jsbronder@gentoo.org> > -sabnzbd-0.7.13-r2.ebuild, > + -sabnzbd-0.7.14.ebuild, +sabnzbd-0.7.16.ebuild, +files/par2cmdline.patch, > + files/sabnzbd.initd, -files/sabnzbd.logrotate: > + Version bump and remove old (#484226). Fix initd script thanks to > eponymous > + (#483786). Remove logrotate (#483672). Fix issues with stable version of > + par2cmdline thanks to dcb (#480302). > > Note that I did make a few edits to your patch, but mainly expanding the > one-line logic stuff for readability. > > Thanks again for all your work and testing! Glad it was useful :) I acutally enjoy messing around with ebuild and associated files. Hmm, maybe I will pick up an un-maintained package when I get some time :) I've actually already created a similar init script for Sickbeard but I don't see that particular application in Portage at the moment; possibly due to it's Alpha status. I may enquire...
Hi eponymous, I'm having problems with this init.d script. I've tried a fresh emerge of the 0.7.16 rebuild (hence default sabnzbd.ini). Running "/etc/init.d/sabnzbd start" yields an OK, but rc-status reports sabnzbd as crashed. Also "ps aux | grep sabnzbd" shows only the ps command... Any ideas?
(In reply to James from comment #26) > Hi eponymous, > > I'm having problems with this init.d script. > > I've tried a fresh emerge of the 0.7.16 rebuild (hence default sabnzbd.ini). > > Running "/etc/init.d/sabnzbd start" yields an OK, but rc-status reports > sabnzbd as crashed. > > Also "ps aux | grep sabnzbd" shows only the ps command... > > Any ideas? Can you attach your sabnzbd logs?
Sorry I just realised I made some errors in my comment 26. To clarify: 1. I removed all the sabnzbd directories 2. Emerged a clean 0.7.16 ebuild 3. Copied my old sabnzbd.ini file into /etc/sabnzbd (using the sabnzbd.ini file included with the package allows sabnzbd to start) When this happens sabnzbd will not start (rc-status shows a crashed state). There are no logs from sabnzbd which leads me to believe it's an error in starting the daemon. When I start sabnzbd with the sabnzb.ini included with the 0.7.16 ebuild: # ps aux | grep sabnzbd sabnzbd 26811 0.2 0.2 2405584 17864 ? Sl 09:33 0:00 /usr/bin/python2.7 SABnzbd.py --config-file /etc/sabnzbd/sabnzbd.ini --logging 1 --daemon --pid /var/run/sabnzb root 26850 0.0 0.0 9060 664 pts/0 S+ 09:33 0:00 grep --colour=auto sabnzbd But when I start sabnzbd with my old sabnzb.ini: # ps aux | grep sabnzbd sabnzbd 26445 0.0 0.0 11960 1552 ? Ss 09:18 0:00 /bin/sh /usr/bin/sabnzbd 563.pid --config-file /etc/sabnzbd/sabnzbd.ini --logging 1 --daemon --pid /var/run/sabnzbd sabnzbd 26452 0.1 0.2 1594452 20984 ? Sl 09:18 0:01 /usr/bin/python2.7 SABnzbd.py 563.pid --config-file /etc/sabnzbd/sabnzbd.ini --logging 1 --daemon --pid /var/run/sabnzbd sabnzbd 26456 0.0 0.0 0 0 ? Z 09:18 0:00 [unrar] <defunct> root 26685 0.0 0.0 9060 668 pts/0 S+ 09:29 0:00 grep --colour=auto sabnzbd Somehow the command to start gets passed an additional "563.pid". The only significance of 563 is that it is a port number of one of my newsgroups account. In addition, when trying to stop the daemon (with my old sabnzbd.ini file) # /etc/init.d/sabnzbd stop * Stopping SABnzbd @ http://0.0.0.0 us.Ngroups.NET:8080 563 ... * Falling back to SIGTERM, this may not work if you restarted via the web interface This makes it look almost identical to what Fab was seeing in Comment 6.
Created attachment 360536 [details] Another sanitized sabnzbd.ini My sabnzbd.ini file that doesn't work with the init.d script
Attached a sanitized version of my sabnzbd.ini file. On a side not, it may not be a CRLF problem. I ran # sed 's/^M$//' sabnzbd.ini.old > sabnzbd.ini to strip out the CRs. But the resultant sabnzbd.ini file does not work with the init.d script.
Hi, I've figured out why this is happening. The sed line in the init script looks only for ports in sections called "[misc]". You have two of those in your file: + One at line #2 + One at line #171 So sed is quite correctly pulling out the port for each section. However, the second instance of [misc] is a sub section of the categories so I think the sed line needs to be changed to just search for [misc], rather than [[misc]] or [[[misc]]] etc... We just need a line anchor at the beginning of the range search. I've made this change and attached a new init script. Justin, would you be able to incorporate this fix? Thanks.
Created attachment 360558 [details] New sabnzbd init script + Fix for duplicate section headings.
Created attachment 360560 [details, diff] New sabnzbd init script (diff against existing init script in 0.7.14) + Fix for duplicate section headings.
(In reply to eponymous from comment #33) > Created attachment 360560 [details, diff] [details, diff] > New sabnzbd init script (diff against existing init script in 0.7.14) > > + Fix for duplicate section headings. There's a lot of whitespace changes in this diff. Would you mind fixing that and attaching a diff with just the relevant code changes? Gentoo initd scripts use 4 spaces to indent and I don't want to miss something while trying to pick out what is whitespace and what is a code change. Thanks,
Created attachment 360600 [details, diff] Patch against init script in 0.7.16 to fix issue with duplicate section headings. + Fix for duplicate section headings.
(In reply to eponymous from comment #35) > Created attachment 360600 [details, diff] [details, diff] > Patch against init script in 0.7.16 to fix issue with duplicate section > headings. > > + Fix for duplicate section headings. (In reply to Justin Bronder from comment #34) > (In reply to eponymous from comment #33) > > Created attachment 360560 [details, diff] [details, diff] [details, diff] > > New sabnzbd init script (diff against existing init script in 0.7.14) > > > > + Fix for duplicate section headings. > > There's a lot of whitespace changes in this diff. Would you mind fixing > that and attaching a diff with just the relevant code changes? Gentoo initd > scripts use 4 spaces to indent and I don't want to miss something while > trying to pick out what is whitespace and what is a code change. > > Thanks, Sorry about that. I'm not sure how that happened actually as we use the same style at work and I've got Vim set up to use 4 spaces for tab-indents. Hmm... Anyway, I've gone ahead and created a patch which is a diff against the current init script in 0.7.16 and should be easier to follow. Hope this helps.
+ 11 Oct 2013; Justin Bronder <jsbronder@gentoo.org> files/sabnzbd.initd: + Update initd script to match the correct [misc] section. Thanks to eponymous + (#483786). +