/rc1.d/K14pms-linux
http://github.com/brinkman83/bashrc · #! · 135 lines · 122 code · 13 blank · 0 comment · 0 complexity · 18913a7e550e026d4f4bbf7236a2b38c MD5 · raw file
- #!/bin/bash
- #
- ### BEGIN INIT INFO
- # Provides: pms-linux
- # Required-Start: $local_fs $remote_fs $network
- # Required-Stop: $local_fs $remote_fs $network
- # Default-Start: 2 3 4 5
- # Default-Stop: 0 1 6
- # Short-Description: Starts pms-linux program.
- # Description: Java Upnp Media Server dedicated to PS3
- ### END INIT INFO
- # Author: Papa Issa DIAKHATE <paissad@gmail.com>
- #
- PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
- DESC="PS3 Media Server"
- NAME=pms-linux
- DAEMON=/usr/bin/$NAME
- SCRIPTNAME=/etc/init.d/$NAME
- CONF_FILE=/usr/share/$NAME/PMS.conf
- test -x $DAEMON || exit 0
- # Be aware of permissions of that directories if you want to change these
- # variables
- LOGDIR=/var/log/$NAME
- PIDFILE=/var/run/$NAME.pid
- DODTIME=10 # Time to wait for the server to die, in seconds
- # If this value is set too low you might not
- # let the program to die gracefully and
- # 'restart' will not work
- # Load the VERBOSE setting and other rcS variables
- . /lib/init/vars.sh
- # Define LSB log_* functions.
- # Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
- . /lib/lsb/init-functions
- ## Include pms-linux defaults if available
- if [ -f /etc/default/$NAME ] ; then
- . /etc/default/$NAME
- fi
- # May we run the init.d script ?
- [ $PMS_START = 1 ] || exit 1
- # We must have a configuration file if we want to start the init.d
- # script
- test -f $CONF_FILE \
- || { echo "Must set a valid configuration file"; exit 1; }
- test -r $CONF_FILE \
- || { echo "The conf file $CONF_FILE is not readable !" ; exit 1; }
- CONF_DIR=`dirname $CONF_FILE`
- #--------------------------------------------------------------------------
- # Some color codes
- txtred=$'\e[0;31m' # Red
- txtylw=$'\e[0;33m' # Yellow
- txtrst=$'\e[0m' # Text Reset
- warnout(){
- echo -e ""$txtylw"Warning:$txtrst $1"
- }
- #--------------------------------------------------------------------------
- running(){
- pid=`pgrep -f 'java .*/usr/share/pms-linux/pms.jar.*'`
- }
- #--------------------------------------------------------------------------
- # We test the existence of the pid file
- test_pidfile(){
- test -e $PIDFILE \
- || warnout "$NAME seems to have been started manually (not by the init.d script)."
- }
- #--------------------------------------------------------------------------
- do_start(){
- running && { warnout "$NAME is already running !"; test_pidfile; exit 0; }
- log_daemon_msg "Starting $DESC : $NAME"
- echo
- start-stop-daemon --start --quiet --background --oknodo \
- --chdir "$CONF_DIR" \
- --make-pidfile --pidfile "$PIDFILE" --exec $DAEMON
- #log_end_msg $?
- }
- #--------------------------------------------------------------------------
- do_stop(){
- running || { warnout "$NAME is NOT running !"; exit 0; }
- log_daemon_msg "Stopping $DESC : $NAME"
- echo
- kill $pid
- rm -f "$PIDFILE"
- #log_end_msg $?
- }
- #--------------------------------------------------------------------------
- do_force-stop(){
- running || { warnout "$NAME is NOT running !"; exit 0; }
- log_daemon_msg "Stopping $DESC : $NAME"
- echo
- kill -9 $pid
- rm -f "$PIDFILE"
- #log_end_msg $?
- }
- #--------------------------------------------------------------------------
- do_status(){
- echo -n " * $NAME is "
- ( running || { echo "NOT running "; exit 0; } )
- ( running && { echo "running (PID -> $(echo $pid))"; test_pidfile; exit 0; } )
- }
- #--------------------------------------------------------------------------
- case "$1" in
- start|stop|force-stop)
- do_${1}
- ;;
- restart|reload|force-reload)
- do_stop
- sleep $DODTIME
- do_start
- ;;
- force-restart)
- do_force-stop
- sleep $DODTIME
- do_start
- ;;
- status)
- do_status
- ;;
- *)
- echo "Usage: $SCRIPTNAME {start|stop|force-stop|restart|force-restart|reload|force-reload|status}"
- exit 1
- ;;
- esac
- exit 0