Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
TV Headend with Raspberry Pi
apt-get update
apt-get install gcc-4.9 g++-4.9 build-essential
apt-get install unzip git-core pkg-config dvb-apps gettext
apt-get install libcurl4-openssl-dev libssl-dev libavahi-client-dev zlib1g-dev libavcodec-dev libavutil-dev libavformat-dev libswscale-dev
export CC=gcc-4.9
export GCC=gcc-4.9
git clone https://github.com/tvheadend/tvheadend
cd tvheadend
./configure
make -j4
make install
groupadd tvheadend
useradd -g tvheadend -G video,audio -m tvheadend
#!/bin/bash
### BEGIN INIT INFO
# Provides:          tvheadend
# Required-Start:    $local_fs $remote_fs $network
# Required-Stop:     $local_fs $remote_fs $network
# Should-Start:      $syslog
# Should-Stop:       $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1
# Short-Description: start/stop tvheadend Server
### END INIT INFO

TVHNAME="tvheadend"
TVHBIN="/usr/local/bin/tvheadend"
TVHUSER="tvheadend"
TVHGROUP="tvheadend"
PIDFILE=/var/run/$TVHNAME.pid

start() {
    if [ -e $PIDFILE ]; then
        PID=$(ps ax | grep -v grep | grep -w $(cat $PIDFILE) | awk '{print $1}')
        if [ -n "$PID" ]; then
            echo "$TVHNAME already running (pid $PID)."
            exit 1
        fi
    fi
    echo -n "Starting $TVHNAME: "
    start-stop-daemon --start --background --pidfile $PIDFILE --make-pidfile --user ${TVHUSER} --exec ${TVHBIN} -- \
        -u ${TVHUSER} -g ${TVHGROUP} -f -C
    echo "Done."
}

stop() {
    if [ -e $PIDFILE ]; then
        PID=$(ps ax | grep -v grep | grep -w $(cat $PIDFILE) | awk '{print $1}')
        if [ -n "$PID" ]; then
            echo -n "Stopping $TVHNAME: "
            start-stop-daemon --stop --quiet --pidfile $PIDFILE --name ${TVHNAME}
            echo "Done."
        else
            echo "$TVHNAME is not running."
        fi
    else
        echo "$TVHNAME is not running."
    fi
}

status() {
    if [ -e $PIDFILE ]; then
        PID=$(ps ax | grep -v grep | grep -w $(cat $PIDFILE) | awk '{print $1}')
        if [ -n "$PID" ]; then
            echo "$TVHNAME is running (pid $PID)."
        else
            echo "$TVHNAME is not running."
            [ -e $PIDFILE ] && exit 1 || exit 3
        fi
    fi
}

case "$1" in
    start) start ;;
    stop) stop ;;
    status) status ;;
    restart) stop && sleep 2 && start ;;
    *) echo "Usage: $0 [start|stop|restart|status]" && exit 1 ;;
esac

exit 0
===============
chmod +x /etc/init.d/tvheadend
update-rc.d tvheadend defaults
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment