Init scripts

From Amahi Wiki
Revision as of 02:37, 20 March 2011 by Bigfoot65 (talk | contribs)
Jump to: navigation, search

This is a compilation of init scripts for various Amahi applications using PHP, JAVA, and Python.

ZNC

#!/bin/sh
#
# znc - Advanced IRC Bouncer INIT script for Fedora #
# chkconfig:   35 99 14
# description: An Advanced IRC bouncer INIT script for \
#              Fedora-CentOS Variants
# Source function library.
. /etc/rc.d/init.d/functions
#
exec=/usr/bin/znc
prog=znc
config=/home/bigfoot/.znc
runas=bigfoot

lockfile=/var/lock/subsys/$prog

start() {
    [ -x $exec ] || exit 5
    echo -n $"Starting $prog: "
    # if not running, start it up here, usually something like "daemon $exec"
    daemon --user $runas "$exec -d $config >/dev/null 2>&1"
    # If you're reckless with your system, comment the line above and
    # uncomment this one below... I just don't get it why
    # daemon "$exec -r -d $config >/dev/null 2>&1"
    retval=$?
    echo
    [ $retval -eq 0 ] && touch $lockfile
    return $retval
}

stop() {
    echo -n $"Stopping $prog: "
    # stop it here, often "killproc $prog"
    killproc $prog -TERM
    retval=$?
    echo
    [ $retval -eq 0 ] && rm -f $lockfile
    return $retval
}

reload() {
    echo -n $"Reloading $prog: "
    # stop it here, often "killproc $prog"
    killproc $prog -HUP
    retval=$?    
    echo
}

restart() {
    stop
    start
}

rh_status() {
    # run checks to determine if the service is running or use generic status
    status $prog
}

rh_status_q() {
    rh_status >/dev/null 2>&1
}

case "$1" in
    start)
        rh_status_q && exit 0
        $1
        ;;
    stop)
        rh_status_q || exit 0
        $1
        ;;
    restart)
        $1
        ;;
    reload)
        rh_status_q || exit 7
        $1
        ;;
    status)
        rh_status
        ;;
    condrestart|try-restart)
        rh_status_q || exit 0
        restart
        ;;
    *)
        echo $"Usage: $0 {start|stop|status|reload|restart|condrestart|try-restart}"
        exit 2
esac

SickBeard

#! /bin/sh

# Author: riyadc
# Basis: Parts of the script based on and inspired by work from
#		daemox (ainer.org), tret (sabnzbd.org), beckstown (xbmc.org),
#		and midgetspy (sickbeard.com).
# Version: 1.0

### BEGIN INIT INFO
# Provides:          sickbeard
# Required-Start:    $all
# Required-Stop:     $all
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: starts, stops, and updates sick beard
# Description:       Sick Beard is an Usenet PVR. For more information 
#			http://www.sickbeard.com
### END INIT INFO
 
 
#Required -- Defaults Provided (only change if you know you need to).
HOST="127.0.0.1" #Set Sick Beard address here.
PORT="8081" #Set Sick Beard port here.
SICKBEARD_HOME=/var/hda/web-apps/sickbeard/html
SICKBEARD_WEBAPPDIR=/var/hda/web-apps/sickbeard
BU1=$SICKBEARD_WEBAPPDIR/.sickbeard_b1 #Set the primary backup location here.
BU2=$SICKBEARD_WEBAPPDIR/.sickbeard_b2 #Set the secondary backup location here.
# Running as apache since amahi-sabnzbd also runs as apache by default.
RUN_AS=apache

# Source function library.
. /etc/init.d/functions
 
#Optional -- Not needed unless you have added a Username and Password to Sick Beard.
SBUSR="" #Set Sick Beard Username (if you use one) here.
SBPWD="" #Set Sick Beard Password (if you use one) here.
 
#Script -- No changes needed below.
case "$1" in
start)
#Start Sick Beard and send all messages to /dev/null.
cd $SICKBEARD_HOME
echo "Starting Sick Beard"
daemon --user $RUN_AS /usr/bin/python $SICKBEARD_HOME/SickBeard.py --quiet > /dev/null 2>&1 &
;;
stop)
#Shutdown Sick Beard.
echo "Stopping Sick Beard"
wget -q --user=$SBUSR --password=$SBPWD "http://$HOST:$PORT/home/shutdown/"
sleep 6s
;;
reload)
#Start update process.
# Shutdown Sick Beard.
echo "Stopping Sick Beard"
wget -q --user=$SBUSR --password=$SBPWD "http://$HOST:$PORT/home/shutdown/"
sleep 6s
  
# Restart Sick Beard quietly and send output to /dev/null.
echo "Restarting Sick Beard"
cd $SICKBEARD_HOME
daemon --user $RUN_AS /usr/bin/python $SICKBEARD_HOME/SickBeard.py --quiet > /dev/null 2>&1 &

;;
update)
#Start update process.
# Shutdown Sick Beard.
echo "Stopping Sick Beard"
wget -q --user=$SBUSR --password=$SBPWD "http://$HOST:$PORT/home/shutdown/"
sleep 6s
 
# Get source and untar it.
echo "Downloading Sick Beard"
cd $SICKBEARD_WEBAPPDIR
wget -q http://github.com/midgetspy/Sick-Beard/tarball/master --no-check-certificate
tar zxf midgetspy-Sick-Beard*
rm -f midgetspy-Sick-Beard*.tar.gz
 
# Make Backups, copy essential files, and install new version.


if [ -d midgetspy-Sick-Beard-* ] 
then
        echo "Backing-up Sick Beard"
        rsync -auq $BU1/ $BU2
        rsync -auq html/ $BU1
        mv html/sickbeard.db midgetspy-Sick-Beard-*/
        mv html/config.ini midgetspy-Sick-Beard-*/
        mv html/autoProcessTV/autoProcessTV.cfg midgetspy-Sick-Beard-*/autoProcessTV/	
        rm -rf html
        rm -rf index.html
        echo "Updating Sick Beard"
        mv midgetspy-Sick-Beard-* html
        chown apache:users html
else 
	echo "Error Update wasn't downloaded"
fi 
 
# Restart Sick Beard quietly and send output to /dev/null.
echo "Restarting Sick Beard"
cd $SICKBEARD_HOME
daemon --user $RUN_AS /usr/bin/python $SICKBEARD_HOME/SickBeard.py --quiet > /dev/null 2>&1 &
;;
*)
echo "Usage: $0 {start|stop|reload|update}"
exit 1
esac
 
exit 0

PS3 Media Server

#!/bin/bash
#
#       /etc/rc.d/init.d/pmsd
#
# Starts the PS3 Media Server
#
# chkconfig: 345 70 80
# description: PS3 Media Server
# processname: java

### BEGIN INIT INFO
# Provides: pmsd
# Required-Start: $syslog $local_fs
# Required-Stop: $syslog $local_fs
# Default-Start:  3 4 5
# Default-Stop: 0 1 6
# Short-Description: start and stop pmsd
# Description: PS3 Media Server
### END INIT INFO

PMSUSER=apache
PMSGROUP=users
JAVA=`which java`

PMS_HOME=/var/hda/web-apps/ps3mediaserver/html
PMS_JAR="$PMS_HOME/pms.jar"
JAVA_OPTS="-Xmx768M -Djava.encoding=UTF-8 -Djava.net.preferIPv4Stack=true -jar $PMS_JAR > /dev/null 2>&1 &"
PMSDPID=/var/run/pmsd.pid

export PMS_HOME


# Source function library.
. /etc/rc.d/init.d/functions

RETVAL=0

#
# See how we were called.
#

start() {

        # Check if pms is already running
        if [ ! -f /var/lock/subsys/pmsd ]; then
                echo -n $"Starting PMS daemon: "
            daemon --user "$PMSUSER" "$JAVA" $JAVA_OPTS
            RETVAL=$?
            [ $RETVAL -eq 0 ] && touch /var/lock/subsys/pmsd
            echo
        fi
        return $RETVAL
}

stop() {

        echo -n $"Stopping PMS daemon: "
        killproc $JAVA
        RETVAL=$?
        [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/pmsd
        echo
    return $RETVAL
}


restart() {
        stop
        start
}

case "$1" in
start)
        start
        ;;
stop)
        stop
        ;;
restart)
        restart
        ;;
status)
        status $JAVA
        RETVAL=$?
        ;;
*)
        echo $"Usage: $0 {start|stop|status|restart}"
        RETVAL=2
esac

exit $RETVAL

uTorrent

#!/bin/bash
#
# init script for Utorrent
#
# chkconfig: 345 96 02
# description: Daemon for utorrent
# processname: utorrent
#

UTORRENT_HOME=/var/hda/web-apps/utorrent/html/
UTORRENT_USER=apache


utorrent_start() {
    echo Starting uTorrent
    mkdir -p /var/run/utorrent
    (cd $UTORRENT_HOME; ./utserver -daemon -logfile /var/log/utorrent.log -pidfile /var/run/utorrent.pid)
}

utorrent_stop() {
    echo Stopping uTorrent
    kill `cat /var/run/utorrent.pid`
}

case "$1" in
    start)
        utorrent_start
        ;;
    stop)
        utorrent_stop
        ;;
    restart)
        utorrent_stop;
        utorrent_start
        ;;
    *)
        echo "Usage: $0 {start|stop|restart}"
        exit1
esac

exit 0

Couch Potato

#! /bin/sh

### BEGIN INIT INFO
# Provides:          CouchPotato application instance
# Required-Start:    $all
# Required-Stop:     $all
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: starts instance of CouchPotato
# Description:       starts instance of CouchPotato using start-stop-daemon
### END INIT INFO
 
#Required -- Defaults Provided (only change if you know you need to).
HOST="127.0.0.1" #Set CouchPotato address here.
PORT="5000" #Set Couch Potato port here.
RUN_AS=apache

# Source function library
. /etc/init.d/functions
 
#Optional -- Unneeded unless you have added a Username and Password to Couch Potato.
CPUSR="" #Set Couch Potato Username (if you use one) here.
CPPWD="" #Set Couch Potato Password (if you use one) here.
 
CPOTATO_HOME=/var/hda/web-apps/cpotato/html

#Script -- No changes needed below.
case "$1" in
start)
#Start Couch Potato
cd $CPOTATO_HOME
echo "Starting Couch Potato"
daemon --user $RUN_AS /usr/bin/python $CPOTATO_HOME/CouchPotato.py -d
;;
stop)
#Shutdown Couch Potato.
echo "Stopping Couch Potato"
wget -q --user=$CPUSR --password=$CPPWD "http://$HOST:$PORT/config/exit/"
sleep 3s
;;
reload)
#Start update process.
# Shutdown Couch Potato.
echo "Stopping Couch Potato"
wget -q --user=$CPUSR --password=$CPPWD "http://$HOST:$PORT/config/exit/"
sleep 3s
  
# Restart Couch Potato quietly and send output to /dev/null.
echo "Restarting Couch Potato"
cd $CPOTATO_HOME
echo "Starting Couch Potato"
daemon --user $RUN_AS /usr/bin/python $CPOTATO_HOME/CouchPotato.py -d      
;;
*)
echo "Usage: $0 {start|stop|reload}"
exit 1
esac
 
exit 0

Monitorix

#!/bin/bash
#
# Copyright (C) 2005-2011 by Jordi Sanfeliu <jordi@fibranet.cat>
#
# monitorix	Starts/Stop the Monitorix daemon
#
# chkconfig: 2345 99 10
# description: A lightweight system monitoring tool
# processname: monitorix
# pidfile: /var/run/monitorix.pid

# Source function library.
. /etc/init.d/functions

RETVAL=0
LOCK="/var/lock/subsys/monitorix"
PROG="monitorix"
CONF="/etc/monitorix.conf"

start() {
	if [ ! -f $LOCK ] ; then
		echo -n $"Starting $PROG: "
		daemon /usr/bin/$PROG -c $CONF && success || failure
		RETVAL=$?
		if [ $RETVAL -eq 0 ] ; then
			pid=`pidof -o %PPID $PROG`
			touch /var/lock/subsys/$PROG
			echo $pid > /var/run/$PROG.pid
			echo
		fi
	fi
}

stop() {
	echo -n $"Stopping $PROG: "
	killproc $PROG
	RETVAL=$?
	rm -f /var/lock/subsys/$PROG
	rm -f /var/run/$PROG
	echo
}

restart() {
	stop
	start
}

case "$1" in
	start)
		start
		;;
	stop)
		stop
		;;
	restart)
		restart
		;;
	status)
        	status $PROG
		;;
	*)
		echo $"Usage: $0 {start|stop|restart|status}"
		exit 1
esac

exit $RETVAL

DropBox

# chkconfig: 345 85 15
# description: Startup script for dropbox daemon
#
# processname: dropboxd
# pidfile: /var/run/dropbox.pid
# config: /etc/sysconfig/dropbox
#
### BEGIN INIT INFO
# Provides: dropboxd
# Required-Start: $local_fs $network $syslog
# Required-Stop: $local_fs $syslog
# Should-Start: $syslog
# Should-Stop: $network $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start up the Dropbox file syncing daemon
# Description:       Dropbox is a filesyncing sevice provided by dropbox.com
#                    This service starts up the dropbox daemon.
### END INIT INFO
# Source function library.
. /etc/rc.d/init.d/functions 
# To configure, add line with DROPBOX_USERS="user1 user2" to /etc/sysconfig/dropbox
# Probably should use a dropbox group in /etc/groups instead.
[ -f /etc/sysconfig/dropbox ] && . /etc/sysconfig/dropbox
prog=dropboxd
lockfile=${LOCKFILE-/var/lock/subsys/$prog}
config=${CONFIG-/etc/sysconfig/dropbox}
RETVAL=0
start() {
   echo -n $"Starting $prog"
   if [ -z $DROPBOX_USERS ] ; then
       echo -n ": unconfigured: $config"
       echo_failure
       echo
       rm -f ${lockfile} ${pidfile}
       RETURN=6
       return $RETVAL
   fi
   for dbuser in $DROPBOX_USERS; do
       daemon --user $dbuser /bin/sh -c "/home/$dbuser/.dropbox-dist/dropboxd&"
   done
   RETVAL=$?
   echo
   [ $RETVAL = 0 ] && touch ${lockfile}
   return $RETVAL
}
status() {
   for dbuser in $DROPBOX_USERS; do
       dbpid=`pgrep -u $dbuser dropbox`
       if [ -z $dbpid ] ; then
           echo "dropboxd for USER $dbuser: not running."
       else
           echo "dropboxd for USER $dbuser: running (pid $dbpid)"
       fi
   done
}
stop() {
   echo -n $"Stopping $prog"
   for dbuser in $DROPBOX_USERS; do
       killproc /home/$dbuser/.dropbox-dist/dropbox
   done
   RETVAL=$?
   echo
   [ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile}
}
# See how we were called.
case "$1" in
   start)
       start
       ;;
   status)
       status
       ;;
   stop)
       stop
       ;;
   restart)
       stop
       start
       ;;
   *)
       echo $"Usage: $prog {start|status|stop|restart}"
       RETVAL=3
esac
exit $RETVAL

phpVirtualBox

#! /bin/sh
PATH=/usr/sbin:/usr/bin:/sbin:/bin
DESC="VirtualBox Web Service"
NAME=vboxwebsrv
SCRIPTNAME=/etc/init.d/$NAME
USER=username
[ -r /etc/default/$NAME ] && . /etc/default/$NAME
[ -f /etc/default/rcS ] && . /etc/default/rcS
. /etc/rc.d/init.d/functions
VBPID=`ps -U ${USER} --no-heading -o pid,cmd | grep vboxwebsrv | grep -v ${SCRIPTNAME} | grep -v  grep | tail -1 | awk '{ print $1 }'`
do_start()
{
  if [ "$VBPID" != "" ] && [ "$VBPID" -gt 0 ]; then
     echo $NAME already running with PID $VBPID
  else
     su ${USER} -c 'vboxwebsrv -b --logfile /dev/null >/dev/null'
  fi
}
do_stop()
{
  if [ "$VBPID" != "" ] && [ "$VBPID" -gt 0 ]; then
       echo Stopping $NAME ...
       kill $VBPID
  else 
       echo $NAME not running
  fi
}
do_status()
{
  if [ "$VBPID" != "" ] && [ "$VBPID" -gt 0 ]; then
       echo Running with pid $VBPID
  else
       echo $NAME not running
  fi
}
case "$1" in
 start)
   [ "$VERBOSE" != no ] && echo "Starting $DESC" "$NAME"
   do_start
   ;;
 stop)
   [ "$VERBOSE" != no ] && echo "Stopping $DESC" "$NAME"
   do_stop
   ;;
 restart|force-reload)
   echo "Restarting $DESC" "$NAME"
   do_stop
   sleep 1
   VBPID=0
   echo Starting $NAME ...
   do_start
   ;;
 status)
   do_status
   ;;
 *)
   echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload|status}" >&2
   exit 3
   ;;
esac


Return to Web App Packaging Notes