init.d service for ordinary app


/ Published in: Bash

This is /etc/sysconfig/chartsrv:
CHARTSRVBASE="/root/chartsrv"
CHARTSRVRUN="/root/chartsrv/chartsrv"
CHARTSRVBIN="/root/chartsrv/chartsrv/chartsrv"
CHARTSRVPID="/var/run/chartsrv.pid"
CHARTSRVLOG="/var/log/chartsrv/chartsrv-$(date +%Y%m%d%H%M%S).log"


Copy this code and paste it in your HTML
  1. #!/bin/sh
  2. ########################################################################
  3. # Begin $rc_base/init.d/
  4. # Description :
  5. # Authors :
  6. # Version : 00.00
  7. # Notes :
  8. ########################################################################
  9.  
  10. . /etc/sysconfig/rc
  11. . ${rc_functions}
  12.  
  13. . /etc/sysconfig/chartsrv
  14. NAME="chartsrv"
  15.  
  16. CHARTSRVPIDDIR="$(dirname "$CHARTSRVPID")"
  17. CHARTSRVLOGDIR="$(dirname "$CHARTSRVLOG")"
  18.  
  19. case "${1}" in
  20. start)
  21. boot_mesg "Starting $NAME..."
  22. [ -d "$CHARTSRVPIDDIR" ] || mkdir -p "$CHARTSRVPIDDIR"
  23. [ -d "$CHARTSRVLOGDIR" ] || mkdir -p "$CHARTSRVLOGDIR"
  24.  
  25. pidofproc -p "${CHARTSRVPID}" "${CHARTSRVBIN}" > /dev/null
  26. case "${?}" in
  27. 0)
  28. log_warning_msg "Unable to continue: ${CHARTSRVBIN} is running"
  29. exit 0 # 4
  30. ;;
  31. 1)
  32. log_warning_msg "Unable to continue: ${CHARTSRVPID} exists"
  33. exit 0 # 4
  34. ;;
  35. 3)
  36. ;;
  37. *)
  38. log_failure_msg "Unknown error code from pidofproc: ${?}"
  39. exit 4
  40. ;;
  41. esac
  42.  
  43. OLD_LD_LIBRARY_PATH="$LD_LIBRARY_PATH"
  44. export LD_LIBRARY_PATH="$CHARTSRVBASE/lib/lib:$CHARTSRVBASE/lib/dashboard:$CHARTSRVBASE/lib/geo:$CHARTSRVBASE/lib/gshhs:$CHARTSRVBASE/lib/property:$CHARTSRVBASE/lib/qpropertyeditor:$CHARTSRVBASE/lib/model:$OLD_LD_LIBRARY_PATH"
  45. OLDWD="$PWD"
  46. cd "$CHARTSRVRUN"
  47. loadproc -f -p "$CHARTSRVPID" /bin/sh -c '"'$CHARTSRVBIN'" '$CHARTSRVARGS' > "'$CHARTSRVLOG'" 2>&1 & echo $! > "'$CHARTSRVPID'"'
  48. cd "$OLDWD"
  49. unset OLDWD
  50. export LD_LIBRARY_PATH="$OLD_LD_LIBRARY_PATH"
  51. unset OLD_LD_LIBRARY_PATH
  52. ;;
  53.  
  54. stop)
  55. boot_mesg "Stopping $NAME..."
  56. killproc -p "$CHARTSRVPID" "$CHARTSRVBIN"
  57. #rm "$CHARTSRVPID"
  58. ;;
  59.  
  60. restart)
  61. ${0} stop
  62. sleep 1
  63. ${0} start
  64. ;;
  65.  
  66. *)
  67. echo "Usage: ${0} {start|stop|reload|restart|status}"
  68. exit 1
  69. ;;
  70. esac
  71.  
  72. # End $rc_base/init.d/

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.