Help with init script?



I'm trying to control a BitTorrent seed from an init script. The original init script (that I wrote) is in /etc/init.d/btseed. It starts and stops a script that is in /usr/local/bin/btseed. This script just starts btlaunchmany, which is used to seed multiple .torrents.

I couldn't get Debian Etch's btlaunchmany to work, so I installed the .deb for the current upstream BitTorrent that's found at http://download.bittorrent.com/dl/ When I run that version's btlaunchmany manually, it works fine.

My problem is that btlaunchmany forks a couple child processes. When I try to stop my daemon, my script itself exits but the child processes don't. I think I could fix this by putting a signal handler in my script that will kill the child processes, but I don't know how to do that. I'm also not sure of what would be the best way to identify the child process' process ID numbers. Perhaps ps | grep would do.

My btseed script takes no command line parameters. Here is the code to start the daemon from /etc/init.d/btseed:

d_start() {
echo -n "$NAME"
start-stop-daemon --start --background --quiet \
--make-pidfile --pidfile "$PIDFILE" \
--chuid nobody \
--exec $DAEMON -- $DAEMONOPTS
}

Here is the code to stop it:

d_stop() {
start-stop-daemon --stop --oknodo --quiet --pidfile "$PIDFILE"
}

I have experimented with giving --signal to start-stop-daemon to try giving different signals to btseed, but nothing seemed to help.

Here is the btseed script:

#!/bin/sh

/usr/bin/btlaunchmany.py --max_upload_rate 128 \
--save_in /var/bittorrent/torrentfiles \
--torrent_dir /var/bittorrent/active \
--minport 50000 \
--maxport 51000 \
--data_dir /var/bittorrent/data | /bin/bzip2 > /var/bittorrent/logs/bt.log.bz2

The reason I didn't just run btlaunchmany.py directly from the init script is that I need to pipe its output through bzip2 and redirect it to a file. I wasn't clear on how I could do that from the start-stop-daemon command line.

Compressing the log is necessary because btlaunchmany.py's output is quite verbose, and will fill a filesystem quickly.

The nonstandard port numbers are an effort to work around ISPs who filter BitTorrent traffic. This doesn't always work, but probably does in some cases. The BitTorrent protocol itself handles the nonstandard port numbers without any trouble.

Thanks for any help you can give me.

Rippit
--
Rippit the Ogg Frog
rippit@xxxxxxxxxxx
http://www.oggfrog.com/

Software isn't the only thing that should be free.
Music should be too, as it once was.


--
To UNSUBSCRIBE, email to debian-user-REQUEST@xxxxxxxxxxxxxxxx with a subject of "unsubscribe". Trouble? Contact listmaster@xxxxxxxxxxxxxxxx



Relevant Pages

  • Re: BitTorrent rpm
    ... >> Well, as i said, I just installed bittorrent today, so I'm certainly no ... >> Are you using Mozilla? ... > a) click on .torrent URL, mozilla open the download panel ... > d) mozilla start script, ...
    (Fedora)
  • command-line bittorrent utility
    ... Must be a command-line utility! ... Must be able to inform the script when the transfer is complete. ... I get errors and exceptions from both the client and server when transferring a file with only two machines participating. ... Surely I am not the first person to want to use bittorrent in a script? ...
    (freebsd-hackers)
  • Re: [SLE] Bittorrent 3.4.2
    ... > Guillermo. ... BitTorrent is just s script. ... Check the headers for your unsubscription address For additional commands send e-mail to suse-linux-e-help@suse.com Also check the archives at http://lists.suse.com Please read the FAQs: suse-linux-e-faq@suse.com ...
    (SuSE)
  • Re: runlevel editor freezes
    ... script here, so we can have a look. ... # LSB compatible service control script; ... # Hard dependencies: This is used by the runlevel editor to determine ... # Specifying the init script ordering, ...
    (alt.os.linux.suse)
  • Re: What does an "export" do?
    ... >> If my script doesnt invoke other scripts or child process, ... > It's very rare that a script doesn't invoke child processes. ... The environment is useful only when you are using the execve ...
    (comp.unix.shell)