From 7d0906c0b1eb4df0a66371268317e07802abaa2b Mon Sep 17 00:00:00 2001 From: ivan Date: Mon, 16 Jun 2003 14:12:48 +0000 Subject: [PATCH] first pass at something ready to try/test --- README | 12 ++++++++---- TODO | 11 +++++++++++ iceplexd | 26 ++++++++++++++++++++++++++ plex.pls | 2 +- yashout | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 5 files changed, 108 insertions(+), 6 deletions(-) diff --git a/README b/README index 8c6d3ba..836545f 100644 --- a/README +++ b/README @@ -24,7 +24,8 @@ On the central multiplexing server: as appropriate: - Database location/user/pass - Path to mp3 file storage on the icecast servers. - - Icecast Port number + - Icecast port number + - - Run iceplexd and configure your init scripts to start it upon boot. - Create an "iceplex" user. - Run "ssh-keygen -t dsa" as the "iceplex" user to genarate SSH keys. @@ -38,21 +39,24 @@ On the central multiplexing server: - Install plex.pls in /cgi-bin/ on the central multiplexing server or main webserver. This file can be installed as or linked to as "plex.m3u" if - desired. + desired. chown this file to the "iceplex", chgrp this file to the + user Apache runs as (www-data or httpd), and chown this file to 4750 On each icecast server: - Create an "iceplex" user. - Copy "/home/iceplex/.ssh/id_dsa.pub" from the central multiplexing server to "/home/iceplex/.ssh/authorized_keys". - - Verify that the + - Verify that the iceplex user on the central multiplexing server can + ssh to this server without a password. - Install libshout C library 1.0.9 and Shout perl interface: + - Set the encoder password in yashout - Install yashout from this archive in /usr/local/bin On end-user webpages: - - Link to: + - Link to (see example.html): Optional, improves stream start latency: diff --git a/TODO b/TODO index 396760c..61be688 100644 --- a/TODO +++ b/TODO @@ -1 +1,12 @@ +- Reliability: yashout errors bubble back to plex.pls & cause server to be + taken out of rotation? + +- Log yashout errors feeding to server somewhere? + +- Configurability of yashoult name/url/genre/description/bitrate/ispublic/etc. + - mp3 file storage should be in hashed directories for scalability + +- for scalability, some amount of iceplexd parallelism: fping for ping? + fork so as to not block on waiting for listeners? + (is one process per server too much?) diff --git a/iceplexd b/iceplexd index 1f1c293..2904be1 100644 --- a/iceplexd +++ b/iceplexd @@ -1 +1,27 @@ #!/usr/bin/perl +# +# iceplexd +# +# Copyright (c) 2003 Ivan Kohler +# All rights reserved. +# This program is free software; you can redistribute it and/or modify it under +# the same terms as Perl itself. + +# TODO, fake it for now :) + +# daemonize + +while (1) { + + # select all servers + # SELECT * FROM iceplex_servers + + foreach my $server ( @servers ) { + #ping , set status + # ask # of listeners + #update database + + } + +sleep 5; +} diff --git a/plex.pls b/plex.pls index a1bd1cc..b3f8d25 100644 --- a/plex.pls +++ b/plex.pls @@ -64,7 +64,7 @@ $dbh->disconnect; my $mountpoint = md5_hex($cgi->remote_host. $$. time. int(rand(4294967296))); #signal encoder to start streaming to mountpoint & wait for confirmation -ssh($server, 'yashout', $filename, $mountpoint ); +ssh($server, 'yashout', $filename, $mountpoint, $port ); #send file back to client browser diff --git a/yashout b/yashout index 6bad0f0..58868fc 100644 --- a/yashout +++ b/yashout @@ -1,11 +1,72 @@ #!/usr/bin/perl +#!/usr/bin/perl -w +# (the Shout library causes warnings if we use -w) # # yashout -# Usage: yashout filename mountpoint +# Usage: yashout filename mountpoint [ port ] # # Copyright (c) 2003 Ivan Kohler # All rights reserved. # This program is free software; you can redistribute it and/or modify it under # the same terms as Perl itself. +use strict; +use subs qw(daemonize); use Shout; + +#read options from commandline +my($filename, $mountpoint, $port) = @ARGV; + +my $conn = new Shout ( + ip => 'localhost', + port => $port || 8000, + mount => $mountpoint, + icy_compat => 0, + dumpfile => undef, + name => 'Fonestream audio', + url => 'http://www.fonestream.com/', + genre => 'talk', + description => 'The easiest way to webcast.', + bitrate => 64, + ispublic => 0, +); +$conn->connect or die "Failed to connect: ". $conn->error; + +open(FILE,"<$filename") or die "Can't open $filename: $!"; + +daemonize(); #fork/disconnect so plex.pls will return to client + +#spool file to server +my( $buffer, $bytes ) = ( '', 0 ); +while ( ( $bytes = read( FILE, $buffer, 4096 ) ) > 0 ) { + $conn->sendData( $buffer ) && next; + # error handling??? + print STDERR "Error while sending: ", $conn->error, "\n"; + last; +} continue { + $conn->sleep; +} + +$conn->disconnect; + +sub daemonize { + chdir "/" or die "Can't chdir to /: $!"; + open STDIN, '/dev/null' or die "Can't read /dev/null: $!"; + defined(my $pid = fork) or die "Can't fork: $!"; + if ( $pid ) { + #print "yashout started with pid $pid\n"; #logging to $log_file\n"; + exit unless $pid_file; + #my $pidfh = new IO::File ">$pid_file" or exit; + #print $pidfh "$pid\n"; + exit; + } + open STDOUT, '>/dev/null' or die "Can't write to /dev/null: $!"; + setsid or die "Can't start a new session: $!"; + open STDERR, '>&STDOUT' or die "Can't dup stdout: $!"; + + #$SIG{__DIE__} = \&_die; + #$SIG{__WARN__} = \&_logmsg; + +} + + -- 2.11.0