Ɛɔıs3
Ɛɔıs3

Reputation: 7853

How to make icecast as service and restart it?

I installed Icecast 2.4.3 on my server using direct download to get the latest version available.

In this way, I don't use the version distributed by my distribution (debian 8) and thus don't have the daemon activated by default.

I found a script that I modified with my corresponding paths, but the execution is in error.

The script icecast.sh :

#!/bin/bash
#
# Init file for Icecast server daemon
#
# chkconfig: 345 55 25
# description: Icecast streaming mp3 server daemon
#
# processname: icecast
# config: /etc/icecast.xml
# pidfile: /var/run/icecast.pid

# source function library
# . /etc/rc.d/init.d/functions : returns an error on debian 8
. /lib/lsb/init-functions

# pull in sysconfig settings
[ -f /etc/sysconfig/icecast ] && . /etc/sysconfig/icecast

RETVAL=0
prog="icecast"

# Some functions to make the below more readable
PREFIX=/usr/local
PATH=$PATH:$PREFIX/bin
PIDFILE=/icecast/icecast.pid
CONF_FILE=/icecast/conf/icecast.xml

[ -f $PREFIX/bin/icecast ] || ( echo Failed to locate icecast binary: $PREFIX/bin/icecast && exit )
[ -f $CONF_FILE          ] || ( echo Failed to locate icecast configuration file: $CONF_FILE && exit )

OPTIONS="-b -c $CONF_FILE"

start()
{
    echo -n $"Starting $prog:"
    ulimit -c unlimited # dump core for debugging purposes
    ulimit -n 32768
    daemon icecast icecast $OPTIONS
    RETVAL=$?
    [ "$RETVAL" = 0 ] && touch /var/lock/subsys/icecast
    echo
    pidof icecast > $PIDFILE
    return $RETVAL
}

stop()
{
    echo -n $"Stopping $prog:"
    killproc icecast -TERM
    RETVAL=$?
    [ "$RETVAL" = 0 ] && rm -f /var/lock/subsys/icecast
    echo
    rm -f $PIDFILE
    return $RETVAL
}

reload()
{
    echo -n $"Reloading $prog:"
    killproc icecast -HUP
    RETVAL=$?
    echo
    return $RETVAL
}

condrestart()
{
    [ -e /var/lock/subsys/icecast ] && restart
    return 0
}

case "$1" in
    start)
        start
        ;;
    stop)
        stop
        ;;
    restart)
        stop
        # wait for listening sockets to clear
        echo "Waiting 5 seconds before restarting..."
        sleep 5
        start
        ;;
    reload)
        reload
        ;;
    condrestart)
        condrestart
        ;;
    status)
        status icecast
        RETVAL=$?
        ;;
    *)
        echo $"Usage: $0 {start|stop|restart|reload|condrestart|status}"
        RETVAL=1
esac
exit $RETVAL

And the error I'm getting when I'm doing sh icecast.sh status :

# sh icecast.sh status
icecast.sh: line 93: status : unknow command

Q1: How do I fix this error?

Q2: How do I get a functional command like icecast restart service?

Q3: What should I do to restart Icecast automatically if the server restarts itself?

Upvotes: 1

Views: 15914

Answers (2)

Alex Paramonov
Alex Paramonov

Reputation: 2730

  1. Install a package from you distro (apt-get install icecast2, yum install icecast, whatever). Usually pakage manager also installs init scripts that will allow you start/stop Icecast.
  2. Get your Icecast patht with which icecast or whereis icecast
  3. Download Icecast, build it from source (like if you need to replace official Icecast with Icecast-kh branch or use your own compilation flags).
  4. Replace the original icecast binary from (2) with the one that you have build. It's always better to backup the original version, though.
  5. /etc/inid/icecast restart or systemctr restart icecast should work now with your version of Icecast.
  6. To make sure your Icecast will start after reboot run systemctl enable icecast

Upvotes: 1

TBR
TBR

Reputation: 2880

The answer is to use the proper package from either debian backports or if you e.g. need TLS support the package from official Xiph.org repositories.

This guarantees, that you will receive package updates without having to monitor releases yourself and figure out necessary changes.

Also please note that the latest release for Linux/Unix at this time is 2.4.2, as 2.4.3 was a Windows only release. The code is identical if compiled for Linux/Unix.

Upvotes: 2

Related Questions