Using Darkice to generate Archive Files
I have successfully set up an archiving system using Darkice. My method uses a feature in Darkice 1.18 which allows a signal to be sent to Darkice to trunk a file and start a new one. The two major advantages of this method are:
- It makes contiguous files without overlap (think multihour, podcasted shows)
- It takes the archiving away from the networking layer and reduces server load
My script, while not perfect, is functioning quite well. I am using Ubuntu linux and I am making a local copy of the archive on an NFS share within the studio network as well as using SCP to post the completed audio file to our webhost for the Station Archive system.
My script, called RadioPlay, is called from within my Darkice init script to set the start time of the archive file. A cron job then runs every hour @ the top of the hour to send a "SIGUSR1" signal to Darkice which pops the file being recorded out and allows Darkice to chug on making a new file. Note that this cron and the script need to run as root since Darkice needs to be run as root. I then write some basic tags using the ID3V2 package since I am storing the files as an AirCheck in addition to posting the file to the Drupal install. Drupal will overwrite the tags on it's import.
My goals for this script are as follows:
- rewrite in perl
- colocate project on a trac server
- add functionality to post metadata to icecast2 and RDS encoder
- fetch metadata from automation system
- add an expiration system for the AirCheck archive
Note that the script posts the files to the Drupal server via SCP, and therefore requires SSH certificates activated. If SCP challenges for a password, the file will not post. See the README file.
| Attachment | Size |
|---|---|
| radioplay.tar_.gz_.txt | 3.11 KB |


Where to locate the file?
Groups.Drupal will not allow me to upload a tar.gz file. Can anybody suggest a location to upload and link to the file?
change the extension?
you could attach it as multiple text files or just rename the *.gz file to *.gz.txt
file attach
Done! Thx.
Cool! I've done the same
Cool!
I've done the same thing too, and was going to post here too but you beat me to it :)
Some my scripts are in perl, so I'll upload them shortly, in case they're of any use to you :)
There is a bug to be aware of in darkice though:
darkice keeps archiving if the network connection to icecast is lost (and picks it up again when the network is back).
BUT if there's no connection to icecast when darkice starts, then it exits.
I appear to not have the
I appear to not have the permissions to post attachments...
Here's the scripts. There's no drupal integration at all yet -- just archiving mp3s which was the key thing.
I'm working on a perl module to hold all the common stuff.
startup (two flavours of this, one for user commandline start, one run on system start which only runs logging because of the above mentioned bug):
#!/usr/bin/perl
# user-run script
# start darkice
# cheap copy of the system start perl script but with differnet log message
#################################################
#
# save the truncated current.mp3 in case we were interrupted
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = gmtime(time - (60 * 5));
$year += 1900; # fix year
$mon++; # fix month
# fix single digits (which in case shell scripts are used, cause breakages
if ( $mon < 10 ) {
$mon = "0$mon";
}
if ( $mday < 10 ) {
$mday = "0$mday";
}
if ( $min < 10 ) {
$min = "0$min";
}
# build filenames
$log_dir = qq[/home/archiver/logging/$year/$mon/$mday];
$log_file = qq[truncated_$hour$min.mp3];
mkdir -p $log_dir;qx[cp /home/archiver/current/current.mp3 $log_dir/$log_file];
#################################################
#
# write to today's log
$log_txt = qq[$log_dir/log];
open(LOG, '>>', $log_txt);
# if the open fails, output is discarded
print LOG qq[$year-$mon-$mday $hour:$min user started darkice\n];
close LOG;
#################################################
#
# run darkice from the SINGLE archive config
# (to avoid darkice bug that will quit if no connection to streamcast)
# store the PID for use by the hourly cron
# shell command to start darkice and store the pid
# single quote to avoid interpolating $!
qx'/usr/bin/darkice -c /home/seaside/conf/stream-archive.conf -v 5 > /var/log/darkice.log 2>&1 & echo $! > /var/run/darkice.pid';
and the hourly.pl script run by cron:
#!/usr/bin/perl
###########################
# archiving script
# contacts the currently running darkice
# and moves the last hour's logged mp3 file to the archive
# script to be run hourly at **:01 (so the cut-off is during the news)
$\ = "\n";
# get date and time from one hour ago
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = gmtime(time - ( 60 * 60 ) );
$year += 1900; # fix year
$mon++; # fix month
# fix single digits (which in case shell scripts are used, cause breakages
if ( $mon < 10 ) {
$mon = "0$mon";
}
if ( $mday < 10 ) {
$mday = "0$mday";
}
if ( $min < 10 ) {
$min = "0$min";
}
#chomp($mon =
date +%m); # hack: get month (with padded 0 and correct number directly from date command# build filenames
$log_dir = qq[/home/archiver/logging/$year/$mon/$mday];
$log_file = qq[$hour.mp3];
#print "logging dir: $log_dir";
#print "logging file: $log_file";
# get pid -- the startup script for darkice set this
$pid =
cat /var/run/darkice.pid;# some checking
#print "logging folder: $log_dir";
#print "saving last hour to: $log_file";
#print "darkice pid: $pid";
# make directory if needed
mkdir -p $log_dir;# for testing only
#$temp_log_file = '/home/seaside/save2.mp3';
# store the cue file for darkice to find --
# tells it where to move the last hour's file
echo "$log_dir/$log_file" > /tmp/darkice.file-0.$pid;print
kill -s sigusr1 $pid;# quick hack until I figure out umask: make the archive file readable
#
chmod o+r $log_dir/$log_file;sleep 5; # hack: sleep a bit in the hope the file shows up by then
chmod 0604, "$log_dir/$log_file";
What would be pretty cool is if this script could get data about the current radio schedule from the station module. It could then choose only to truncate darkice when there's a change of radio program, so you'd get a single MP3 of the whole show.
Issue with Darkice and sigusr1 in FreeBSD
Hi Guys,
Your posts have been really helpful; I've taken some parts from both of them to create our audio log files for our campus and community radio station in Vancouver BC. Most of the time i've had to put into changing the files is because the BSD system is a little different.
The problem that I'm having is that when i send sigusr1 (USR1 in bsd) to darkice, i get the error:
28-Feb-2008 19:00:00 cutting
28-Feb-2008 19:00:00 cutting ends
28-Feb-2008 19:00:00 couldn't move file /tmp/current.mp3 to /var/log/broadcast/2008/02/28/18.mp3
Darkice is running as root, so there shouldn't be any permissions issues. The following is the C++ code that generates the issue:
[quote]
try {
std::string archiveFileName = getArchiveFileName();
if (::rename(fileName, archiveFileName.c_str()) != 0) {
reportEvent(2, "couldn't move file", fileName,
"to", archiveFileName);
}
} catch ( Exception &e ) {
reportEvent(2, "error during archive cut", e);
}
[/quote]
Do you have any idea why ::rename(fileName,archiveFileName.c_str()) is returning 0?
Doug
Code Change
Hi All,
I found out from a friend of mine that the bug came from the rename function not being able to copy files across filesystems. He patched the issue and sent it to the darkice developers for implementation.
See: http://darkice.tyrell.hu/trac/ticket/37
Argh
I've got this running (with the scp stuff commented out), but on today's new replacement logging box, for some reason 'kill -s 10 $PID' is actually killing darkice, not merely signaling it.
Anybody seen this before?
Old version of darkice, as
Old version of darkice, as it turns out.
I now just need to figure out what on earth darkice thinks it's doing when it discards the 9MB it was using to hold ten-minute chunks. Because it's certainly not handing it back to the OS and after one day the machine's gone into swap. Suck.