PageRenderTime 197ms CodeModel.GetById 186ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

/rc6.d/K14pms-linux

http://github.com/brinkman83/bashrc
#! | 135 lines | 122 code | 13 blank | 0 comment | 0 complexity | 18913a7e550e026d4f4bbf7236a2b38c MD5 | raw file
  1#!/bin/bash
  2#
  3### BEGIN INIT INFO
  4# Provides:          pms-linux 
  5# Required-Start:    $local_fs $remote_fs $network
  6# Required-Stop:     $local_fs $remote_fs $network
  7# Default-Start:     2 3 4 5
  8# Default-Stop:      0 1 6
  9# Short-Description: Starts pms-linux program.
 10# Description:       Java Upnp Media Server dedicated to PS3
 11### END INIT INFO
 12
 13# Author: Papa Issa DIAKHATE <paissad@gmail.com>
 14#
 15PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
 16DESC="PS3 Media Server"
 17NAME=pms-linux
 18DAEMON=/usr/bin/$NAME
 19SCRIPTNAME=/etc/init.d/$NAME
 20CONF_FILE=/usr/share/$NAME/PMS.conf
 21
 22test -x $DAEMON || exit 0
 23
 24# Be aware of permissions of that directories if you want to change these
 25# variables
 26LOGDIR=/var/log/$NAME
 27PIDFILE=/var/run/$NAME.pid
 28DODTIME=10                   # Time to wait for the server to die, in seconds
 29# If this value is set too low you might not
 30# let the program to die gracefully and
 31# 'restart' will not work
 32
 33# Load the VERBOSE setting and other rcS variables
 34. /lib/init/vars.sh
 35
 36# Define LSB log_* functions.
 37# Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
 38. /lib/lsb/init-functions
 39
 40## Include pms-linux defaults if available
 41if [ -f /etc/default/$NAME ] ; then
 42		. /etc/default/$NAME
 43fi
 44
 45# May we run the init.d script ?
 46[ $PMS_START = 1 ] || exit 1
 47
 48# We must have a configuration file if we want to start the init.d 
 49# script 
 50test -f $CONF_FILE \
 51|| { echo "Must set a valid configuration file"; exit 1; }
 52test -r $CONF_FILE \
 53|| { echo "The conf file $CONF_FILE is not readable !" ; exit 1; }
 54
 55CONF_DIR=`dirname $CONF_FILE`
 56
 57#--------------------------------------------------------------------------
 58# Some color codes
 59txtred=$'\e[0;31m' # Red
 60txtylw=$'\e[0;33m' # Yellow
 61txtrst=$'\e[0m'    # Text Reset
 62
 63warnout(){
 64    echo -e ""$txtylw"Warning:$txtrst $1"
 65}
 66#--------------------------------------------------------------------------
 67running(){
 68	pid=`pgrep -f 'java .*/usr/share/pms-linux/pms.jar.*'`
 69}
 70#--------------------------------------------------------------------------
 71# We test the existence of the pid file
 72test_pidfile(){
 73	test -e $PIDFILE \
 74	|| warnout "$NAME seems to have been started manually (not by the init.d script)."
 75}
 76#--------------------------------------------------------------------------
 77do_start(){
 78	running && { warnout "$NAME is already running !"; test_pidfile; exit 0; }
 79	log_daemon_msg "Starting $DESC : $NAME"
 80	echo
 81	start-stop-daemon --start --quiet --background --oknodo \
 82	--chdir "$CONF_DIR" \
 83	--make-pidfile --pidfile "$PIDFILE" --exec $DAEMON 
 84	#log_end_msg $?
 85}
 86#--------------------------------------------------------------------------
 87do_stop(){
 88	running || { warnout "$NAME is NOT running !"; exit 0; }	
 89	log_daemon_msg "Stopping $DESC : $NAME"
 90	echo
 91	kill $pid 
 92	rm -f "$PIDFILE"
 93	#log_end_msg $?
 94}
 95#--------------------------------------------------------------------------
 96do_force-stop(){
 97	running || { warnout "$NAME is NOT running !"; exit 0; }	
 98	log_daemon_msg "Stopping $DESC : $NAME"
 99	echo
100	kill -9 $pid 
101	rm -f "$PIDFILE"
102	#log_end_msg $?
103}
104#--------------------------------------------------------------------------
105do_status(){
106	echo -n " * $NAME is "
107	( running || { echo "NOT running "; exit 0; } )
108	( running && { echo "running (PID -> $(echo $pid))"; test_pidfile; exit 0; } )
109}
110#--------------------------------------------------------------------------
111case "$1" in 
112
113	start|stop|force-stop)
114	do_${1}
115	;;
116	restart|reload|force-reload)
117	do_stop
118	sleep $DODTIME 
119	do_start
120	;;
121	force-restart)
122	do_force-stop
123	sleep $DODTIME
124	do_start
125	;;
126	status)
127	do_status
128	;;
129	*)
130	echo "Usage: $SCRIPTNAME {start|stop|force-stop|restart|force-restart|reload|force-reload|status}"
131	exit 1
132	;;
133esac
134
135exit 0