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