Потребовалось вести запись нескольких радиостанций. Были куплены три автомобильных приемников с линейным выходом, со склада взят старый комп и в него воткнули две старых pci звуковых карты.
1. Установил debian и установлены дополнительные пакеты:
icecast2
darkice (Возможно понадобится: Darkice + aacPlus на Debian)
alsa-base
streamripper
2. Настраиваем звуковые карты с помощью alsamixer
3. Настраиваем icecast2, там все стандартно. Добавляем в автозагрузку используя update-rc.d
4. Настраиваем darkice, тут интереснее (почему и родилась статья).
4.0. Настраиваем звуковые карты читаем статью.
4.1. Создаем три конфигурационных файла:
# cat /etc/darkice.cfg | grep -v ^# | grep -v ^$ | grep -v ^\ *#
[general]
duration        = 0        # duration of encoding, in seconds. 0 means forever
bufferSecs      = 1         # size of internal slip buffer, in seconds
reconnect       = yes       # reconnect to the server(s) if disconnected
[input]
device          = hw:0,0  # OSS DSP soundcard device for the audio input
sampleRate      = 44100     # sample rate in Hz. try 11025, 22050 or 44100
bitsPerSample   = 16        # bits per sample. try 16
channel         = 2         # channels. 1 = mono, 2 = stereo
[icecast2-0]
bitrateMode     = abr       # average bit rate
format          = vorbis    # format of the stream: ogg vorbis
bitrate         = 128        # bitrate of the stream sent to the server
server          = 127.0.0.1
port            = 8000      # port of the IceCast2 server, usually 8000
password        = mypass    # source password to the IceCast2 server
mountPoint      = radio1  # mount point of this stream on the IceCast2 server
name            = Radio 1
description     = Radio1
genre           = my own    # genre of the stream
public          = yes       # advertise this stream?
# cat /etc/darkice2.cfg | grep -v ^# | grep -v ^$ | grep -v ^\ *#
[general]
duration        = 0        # duration of encoding, in seconds. 0 means forever
bufferSecs      = 1         # size of internal slip buffer, in seconds
reconnect       = yes       # reconnect to the server(s) if disconnected
[input]
device          = hw:1,0,0  # OSS DSP soundcard device for the audio input
sampleRate      = 44100     # sample rate in Hz. try 11025, 22050 or 44100
bitsPerSample   = 16        # bits per sample. try 16
channel         = 2         # channels. 1 = mono, 2 = stereo
[icecast2-0]
bitrateMode     = abr       # average bit rate
format          = vorbis    # format of the stream: ogg vorbis
bitrate         = 128        # bitrate of the stream sent to the server
server          = 127.0.0.1
port            = 8000      # port of the IceCast2 server, usually 8000
password        = mypass    # source password to the IceCast2 server
mountPoint      = radio2  # mount point of this stream on the IceCast2 server
name            = Radio 2
description     = Radio2
genre           = my own    # genre of the stream
public          = yes       # advertise this stream?
# cat /etc/darkice3.cfg | grep -v ^# | grep -v ^$ | grep -v ^\ *#
[general]
duration        = 0        # duration of encoding, in seconds. 0 means forever
bufferSecs      = 1         # size of internal slip buffer, in seconds
reconnect       = yes       # reconnect to the server(s) if disconnected
[input]
device          = hw:2,0  # OSS DSP soundcard device for the audio input
sampleRate      = 44100     # sample rate in Hz. try 11025, 22050 or 44100
bitsPerSample   = 16        # bits per sample. try 16
channel         = 2         # channels. 1 = mono, 2 = stereo
[icecast2-0]
bitrateMode     = abr       # average bit rate
format          = vorbis    # format of the stream: ogg vorbis
bitrate         = 128        # bitrate of the stream sent to the server
server          = 127.0.0.1
port            = 8000      # port of the IceCast2 server, usually 8000
password        = mypass    # source password to the IceCast2 server
mountPoint      = radio3  # mount point of this stream on the IceCast2 server
name            = Radio 3
description     = Radio 3
genre           = my own    # genre of the stream
public          = yes       # advertise this stream?
4.2. Создаем пользователей darkice, darkice2, darkice3 и добавляем их в группу audio
4.3. Скрипты запуска (стандартный не может запускать несколько копий под разными пользователями):
# cat /etc/init.d/darkice
#!/bin/sh
#
### BEGIN INIT INFO
# Provides:          darkice
# Required-Start:    $network $local_fs $remote_fs icecast2
# Required-Stop:     $network $local_fs $remote_fs icecast2
# Should-Start:
# Should-Stop:
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Live audio streamer
# Description:       DarkIce is an IceCast, IceCast2 and ShoutCast
#                    live audio streamer.
### END INIT INFO
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/bin/darkice
NAME=darkice
DESC="Darkice live audio streamer"
test -x $DAEMON || exit 0
# Defaults
CONFIGFILE="/etc/darkice.cfg"
USER=darkice
GROUP=darkice
PIDFILE="/var/run/$NAME/$NAME.pid"
#set -e
case "$1" in
  start)
        mkdir -p `dirname "$PIDFILE"`
        chown -R $USER:$GROUP `dirname "$PIDFILE"`
        echo -n "Starting $DESC: "
        start-stop-daemon  --start --background --chuid $USER:$GROUP --make-pidfile --pidfile $PIDFILE --exec $DAEMON -- -c "$CONFIGFILE"
        echo "$NAME."
        ;;
  stop)
        echo -n "Stopping $DESC: "
        start-stop-daemon --stop --oknodo --quiet --pidfile $PIDFILE --exec $DAEMON
        echo "$NAME."
        rm -f $PIDFILE
        ;;
  restart|force-reload)
        $0 stop
        $0 start
        ;;
  status)
        if [ -r $PIDFILE ]; then
            echo "$NAME started"
            echo "Pid: " `cat $PIDFILE`
        else
            echo "$NAME stoped"
        fi
        ;;
  *)
        echo "Usage: $0 {start|stop|restart|reload|force-reload}" >&2
        exit 1
        ;;
esac
exit 0
# cat /etc/init.d/darkice2
#!/bin/sh
#
### BEGIN INIT INFO
# Provides:          darkice2
# Required-Start:    $network $local_fs $remote_fs icecast2
# Required-Stop:     $network $local_fs $remote_fs icecast2
# Should-Start:
# Should-Stop:
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Live audio streamer
# Description:       DarkIce is an IceCast, IceCast2 and ShoutCast
#                    live audio streamer.
### END INIT INFO
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/bin/darkice
NAME=darkice2
DESC="Darkice live audio streamer"
test -x $DAEMON || exit 0
# Defaults
CONFIGFILE="/etc/darkice2.cfg"
USER=darkice2
GROUP=darkice2
PIDFILE="/var/run/$NAME/$NAME.pid"
#set -e
case "$1" in
  start)
        mkdir -p `dirname "$PIDFILE"`
        chown -R $USER:$GROUP `dirname "$PIDFILE"`
        echo -n "Starting $DESC: "
        start-stop-daemon  --start --background --chuid $USER:$GROUP --make-pidfile --pidfile $PIDFILE --exec $DAEMON -- -c "$CONFIGFILE"
        echo "$NAME."
        ;;
  stop)
        echo -n "Stopping $DESC: "
        start-stop-daemon --stop --oknodo --quiet --pidfile $PIDFILE --exec $DAEMON
        echo "$NAME."
        rm -f $PIDFILE
        ;;
  restart|force-reload)
        $0 stop
        $0 start
        ;;
  status)
        if [ -r $PIDFILE ]; then
            echo "$NAME started"
            echo "Pid: " `cat $PIDFILE`
        else
            echo "$NAME stoped"
        fi
        ;;
  *)
        echo "Usage: $0 {start|stop|restart|reload|force-reload}" >&2
        exit 1
        ;;
esac
exit 0
Аналогично для darkice3.
4.4. Добавляем скрипты в автозагрузку используя update-rc.d
update-rc.d darkice1 defaults
update-rc.d darkice2 defaults
update-rc.d darkice3 defaults
service darkice1 start
service darkice2 start
service darkice3 start
5. Скрипты для записи.
$ cat rec.radio1.sh
#!/bin/sh
DATE=`date +%Y-%m-%d_%H-%M`
cd /home/air/radio1
/usr/bin/streamripper http://127.0.0.1:8000/radio1.m3u \
-a /home/air/radio1/$DATE -A -s -z -l 3720 -i --quiet
/usr/bin/find /home/air/radio1 -name "*.ogg" -ctime +35d -delete
$ cat rec.radio2.sh
#!/bin/sh
/home/air/radio2
DATE=`date +%Y-%m-%d_%H-%M`
/usr/bin/streamripper http://127.0.0.1:8000/radio2.m3u \
-a /home/air/radio2/$DATE -A -s -z -l 3720 -i --quiet
/usr/bin/find /home/air/radio2 -name "*.ogg" -ctime +35d -delete
Аналогично для rec.radio3.sh
6. Прописываем cскрипты записи в crontab
$ cronatb -e
# m h  dom mon dow   command
59 * * * * /bin/bash /home/air/rec.radio1.sh
59 * * * * /bin/bash /home/air/rec.radio2.sh
59 * * * * /bin/bash /home/air/rec.radio3.sh
Все 🙂