wiki:IndyTubeInitScript

Version 4 (modified by vik, 5 years ago) (diff)

--

To start and stop indytube using your OS's init system (works on debian-style systems, YMMV on other systems), you need two files: /etc/default/indytube which set the location of the indytube directory/ies, and /etc/init.d/indytube, which does the starting and stopping. After copying these files, run "chmod +x /etc/init.d/indytube" then "update-rc.d indytube defaults"

/etc/default/indytube needs just one line - the full path to indytube. Multiple instances are seperated by a space

# Location of indytube instances; seperate by a space if you have more than one
# e.g INDY_INSTANCES="/foo/bar/indytube1 /foo/bar/indytube2"
INDY_INSTANCES="/opt/plumi-0.2.3-final/indytube"

# This has to be the same as what's defined for ENCODER_LOCKFILE_BASE in indytube.conf. 
# indytube.conf should be modified so the lockfile is stored in the instance's directory,
# so $INDY_INSTANCE/$LOCKFILE is the same path as ENCODER_LOCKFILE_BASE in indytube.conf
LOCKFILE="indytube-encoder.lock"

/etc/init.d/indytube shouldn't need modification; you can overwrite variables in /etc/default/indytube

#! /bin/sh -e
#### BEGIN INIT INFO
# Provides:          indytube
# Required-Start:    $local_fs $remote_fs $network $syslog
# Required-Stop:     $local_fs $remote_fs $network $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Controls indytube
# Description:       Starts and stops the indytube process
### END INIT INFO
#
# Author:    Victor Rajewski
#
set -e

PATH=/bin:/usr/bin:/sbin:/usr/sbin

DAEMON=indytube.py
LOGFILE=run_indytube.log
PIDFILE=indytube.pid

#
# Configuration file for indytube instances. Seperate instances by a space
# At miniumum should have:
# 
# INDY_INSTANCES="/opt/plumi-0.2.3-final/indytube"
# LOCKFILE="indytube-encoder.lock" #must be same as defined in indytube.conf
conf="/etc/default/indytube"
test -f "$conf" && . "$conf"

. /lib/lsb/init-functions

do_start()
{
	rm -f $instance/$LOCKFILE
	$instance/$DAEMON >$instance/$LOGFILE 2>&1 &
	echo $! > $instance/$PIDFILE
        log_end_msg 0
}

do_stop()
{
	kill -9 `cat $instance/$PIDFILE`
	rm $instance/$PIDFILE
        log_end_msg 0
}

for instance in $INDY_INSTANCES ; do
    RETVAL=0
    case "$1" in
    start)
        log_daemon_msg "Starting: $instance"
	do_start
        ;;
    stop)
        log_daemon_msg "Stopping: $instance"
	do_stop
        ;;
    restart)
        log_daemon_msg "Restarting: $instance"
	do_stop
	sleep 2
	do_start
        ;;
    *)
        echo "Usage: /etc/init.d/indytube {start|stop|restart}"
        exit 1
        ;;
    esac
done