Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 483786 - net-nntp/sabnzbd: Improved init script for SABnzbd with fixes
Summary: net-nntp/sabnzbd: Improved init script for SABnzbd with fixes
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: All Linux
: High normal (vote)
Assignee: Justin Bronder (RETIRED)
URL:
Whiteboard:
Keywords: PATCH
Depends on:
Blocks:
 
Reported: 2013-09-05 19:08 UTC by eponymous
Modified: 2013-10-11 15:27 UTC (History)
2 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
New sabnzbd init script (sabnzbd,1.88 KB, text/plain)
2013-09-05 19:08 UTC, eponymous
Details
New sabnzbd init script (diff against exiting init script in 0.7.14) (sabnzbd.patch,3.37 KB, patch)
2013-09-05 19:08 UTC, eponymous
Details | Diff
sabnzbd.log (sabnzbd.log,5.02 KB, text/plain)
2013-09-06 09:06 UTC, Fab
Details
sanitized sabnzbd.ini (sabnzbd.ini,3.64 KB, application/x-wine-extension-ini)
2013-09-06 09:24 UTC, Fab
Details
New sabnzbd init script (sabnzbd,1.90 KB, text/plain)
2013-09-07 11:13 UTC, eponymous
Details
New sabnzbd init script (diff against existing init script in 0.7.14) (sabnzbd.patch,3.38 KB, patch)
2013-09-07 11:15 UTC, eponymous
Details | Diff
New sabnzbd init script (sabnzbd,1.90 KB, text/plain)
2013-09-08 13:41 UTC, eponymous
Details
New sabnzbd init script (diff against existing init script in 0.7.14) (sabnzbd.patch,3.38 KB, patch)
2013-09-08 13:42 UTC, eponymous
Details | Diff
New sabnzbd init script (sabnzbd,1.90 KB, text/plain)
2013-09-08 14:38 UTC, eponymous
Details
New sabnzbd init script (diff against existing init script in 0.7.14) (sabnzbd.patch,3.39 KB, patch)
2013-09-08 14:39 UTC, eponymous
Details | Diff
New sabnzbd init script (sabnzbd,1.91 KB, text/plain)
2013-09-08 15:47 UTC, eponymous
Details
New sabnzbd init script (diff against existing init script in 0.7.14) (sabnzbd.patch,3.40 KB, patch)
2013-09-08 15:48 UTC, eponymous
Details | Diff
New sabnzbd init script (sabnzbd,2.08 KB, text/plain)
2013-09-13 20:26 UTC, eponymous
Details
New sabnzbd init script (diff against existing init script in 0.7.14) (sabnzbd.patch,3.71 KB, patch)
2013-09-13 20:27 UTC, eponymous
Details | Diff
Another sanitized sabnzbd.ini (sabnzbd.ini,5.23 KB, text/plain)
2013-10-10 02:08 UTC, James Chew
Details
New sabnzbd init script (sabnzbd,2.08 KB, text/plain)
2013-10-10 09:43 UTC, eponymous
Details
New sabnzbd init script (diff against existing init script in 0.7.14) (sabnzbd.patch,3.71 KB, patch)
2013-10-10 09:44 UTC, eponymous
Details | Diff
Patch against init script in 0.7.16 to fix issue with duplicate section headings. (sabnzbd.patch,358 bytes, patch)
2013-10-10 20:03 UTC, eponymous
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description eponymous 2013-09-05 19:08:21 UTC
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.
Comment 1 eponymous 2013-09-05 19:08:58 UTC
Created attachment 357962 [details, diff]
New sabnzbd init script (diff against exiting init script in 0.7.14)
Comment 2 eponymous 2013-09-05 19:13:23 UTC
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. :)
Comment 3 eponymous 2013-09-05 19:17:49 UTC
Title changed to be somewhat less presumptious - though I'm fairly sure this init script is working after my rigorous testing.
Comment 4 Fab 2013-09-06 08:17:20 UTC
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.
Comment 5 eponymous 2013-09-06 08:46:09 UTC
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.
Comment 6 Fab 2013-09-06 09:06:10 UTC
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
Comment 7 eponymous 2013-09-06 09:11:39 UTC
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!
Comment 8 Fab 2013-09-06 09:24:22 UTC
Created attachment 358020 [details]
sanitized sabnzbd.ini
Comment 9 eponymous 2013-09-07 11:13:42 UTC
Created attachment 358152 [details]
New sabnzbd init script

+ Fixed the sed line to limit the range of substitution
Comment 10 eponymous 2013-09-07 11:15:05 UTC
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
Comment 11 eponymous 2013-09-07 11:15:43 UTC
(In reply to Fab from comment #8)
> Created attachment 358020 [details]
> sanitized sabnzbd.ini

Hi Fab,

Can you test the updated script?

Thanks!
Comment 12 Fab 2013-09-07 17:31:21 UTC
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
Comment 13 eponymous 2013-09-08 13:41:45 UTC
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)
Comment 14 eponymous 2013-09-08 13:42:44 UTC
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)
Comment 15 Fab 2013-09-08 14:20:58 UTC
Now it works fine. Thanks !
Comment 16 eponymous 2013-09-08 14:38:14 UTC
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.
Comment 17 eponymous 2013-09-08 14:39:26 UTC
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.
Comment 18 eponymous 2013-09-08 14:40:32 UTC
(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.
Comment 19 eponymous 2013-09-08 15:47:21 UTC
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. :)
Comment 20 eponymous 2013-09-08 15:48:02 UTC
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. :)
Comment 21 eponymous 2013-09-08 15:52:26 UTC
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.
Comment 22 eponymous 2013-09-13 20:26:10 UTC
Created attachment 358602 [details]
New sabnzbd init script

+ Added in graceful handling of race condition when restarting.
Comment 23 eponymous 2013-09-13 20:27:13 UTC
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.
Comment 24 Justin Bronder (RETIRED) gentoo-dev 2013-10-08 23:21:36 UTC
+*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!
Comment 25 eponymous 2013-10-09 07:57:50 UTC
(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...
Comment 26 James Chew 2013-10-09 16:37:12 UTC
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?
Comment 27 Justin Bronder (RETIRED) gentoo-dev 2013-10-09 22:13:09 UTC
(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?
Comment 28 James Chew 2013-10-10 01:41:41 UTC
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.
Comment 29 James Chew 2013-10-10 02:08:32 UTC
Created attachment 360536 [details]
Another sanitized sabnzbd.ini

My sabnzbd.ini file that doesn't work with the init.d script
Comment 30 James Chew 2013-10-10 02:11:30 UTC
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.
Comment 31 eponymous 2013-10-10 09:42:34 UTC
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.
Comment 32 eponymous 2013-10-10 09:43:52 UTC
Created attachment 360558 [details]
New sabnzbd init script

+ Fix for duplicate section headings.
Comment 33 eponymous 2013-10-10 09:44:23 UTC
Created attachment 360560 [details, diff]
New sabnzbd init script (diff against existing init script in 0.7.14)

+ Fix for duplicate section headings.
Comment 34 Justin Bronder (RETIRED) gentoo-dev 2013-10-10 14:06:33 UTC
(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,
Comment 35 eponymous 2013-10-10 20:03:03 UTC
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.
Comment 36 eponymous 2013-10-10 20:04:56 UTC
(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.
Comment 37 Justin Bronder (RETIRED) gentoo-dev 2013-10-11 15:27:28 UTC
+  11 Oct 2013; Justin Bronder <jsbronder@gentoo.org> files/sabnzbd.initd:
+  Update initd script to match the correct [misc] section. Thanks to eponymous
+  (#483786).
+