Advertisement
Guest User

Untitled

a guest
Jul 12th, 2012
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.60 KB | None | 0 0
  1. #! /bin/sh
  2. ### BEGIN INIT INFO
  3. # Provides: tc-daemon
  4. # Required-Start: networking
  5. # Required-Stop: networking
  6. # Default-Start: 2 3 5
  7. # Default-Stop: 0 1 6
  8. # Short-Description: Start the trinity core daemon.
  9. ### END INIT INFO
  10.  
  11. # Author: Rob Howell's script
  12.  
  13. # Do NOT "set -e"
  14.  
  15. # ----- CONFIGURATION -----
  16. # The name of the user that should run Trinity Core.
  17. USERNAME=USERNAME
  18.  
  19. # The folder where the worldserver and authserver startup scripts are stored.
  20. TRINITY_HOME="/PATH/TRINTY/BIN/"
  21.  
  22. # The arguments passed on to Trinity-daemon.
  23. #TRINITY_ARGS=""
  24. # ----- END OF CONFIGURATION -----
  25.  
  26. PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
  27. DESC="trinitycore"
  28. NAME1=tcworld-daemon
  29. NAME2=tcauth-daemon
  30. DAEMON1=worldserver
  31. DAEMON2=authserver
  32. PIDFILE1=/var/run/$NAME1.pid
  33. PIDFILE2=/var/run/$NAME2.pid
  34. SCRIPTNAME=/etc/init.d/$NAME
  35.  
  36. # Exit if the package is not installed
  37. [ -x "$DAEMON1" ] || exit 0
  38. # Exit if the package is not installed
  39. [ -x "$DAEMON2" ] || exit 0
  40. #
  41. # Function that starts the daemon/service
  42. #
  43.  
  44. do_start()
  45. {
  46. # Export the Trinity Home directory, if set
  47. if [ -n "$TRINITY_HOME" ]; then
  48. export TRINITY_HOME
  49. fi
  50.  
  51. # Return
  52. # 0 if daemon has been started
  53. # 1 if daemon was already running
  54. # 2 if daemon could not be started
  55. start-stop-daemon --chuid $USERNAME --start --pidfile $PIDFILE1 --make-pidfile \
  56. --exec $DAEMON1 --background --test -- -f $TRINITY_ARGS > /dev/null \
  57. || return 1
  58. start-stop-daemon --chuid $USERNAME --start --pidfile $PIDFILE2 --make-pidfile \
  59. --exec $DAEMON2 --background --test -- -f $TRINITY_ARGS > /dev/null \
  60. || return 1
  61. start-stop-daemon --chuid $USERNAME --start --pidfile $PIDFILE1 --make-pidfile \
  62. --exec $DAEMON1--background -- -f $TRINITY_ARGS \
  63. || return 2
  64. start-stop-daemon --chuid $USERNAME --start --pidfile $PIDFILE2 --make-pidfile \
  65. --exec $DAEMON2--background -- -f $TRINITY_ARGS \
  66. || return 2
  67. }
  68.  
  69. #
  70. # Function that stops the daemon/service
  71. #
  72. do_stop()
  73. {
  74. # Return
  75. # 0 if daemon has been stopped
  76. # 1 if daemon was already stopped
  77. # 2 if daemon could not be stopped
  78. # other if a failure occurred
  79. start-stop-daemon --stop --quiet --retry=TERM/10/KILL/5 --pidfile $PIDFILE1 --exec $DAEMON1
  80. RETVAL="$?"
  81. [ "$RETVAL" = 2 ] && return 2
  82. start-stop-daemon --stop --quiet --retry=TERM/10/KILL/5 --pidfile $PIDFILE2 --exec $DAEMON2
  83. RETVAL="$?"
  84. [ "$RETVAL" = 2 ] && return 2
  85.  
  86. # Wait for children to finish too if this is a daemon that forks
  87. # and if the daemon is only ever run from this initscript.
  88. # If the above conditions are not satisfied then add some other code
  89. # that waits for the process to drop all resources that could be
  90. # needed by services started subsequently. A last resort is to
  91. # sleep for some time.
  92.  
  93. start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON2
  94. [ "$?" = 2 ] && return 2
  95. start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON2
  96. [ "$?" = 2 ] && return 2
  97.  
  98. # Many daemons don't delete their pidfiles when they exit.
  99. rm -f $PIDFILE1
  100. rm -f $PIDFILE2
  101. return "$RETVAL"
  102. }
  103.  
  104. case "$1" in
  105. start)
  106. echo "Starting $DESC" "$NAME..."
  107. do_start
  108. case "$?" in
  109. 0|1) echo " Starting $DESC $NAME succeeded" ;;
  110. *) echo " Starting $DESC $NAME failed" ;;
  111. esac
  112. ;;
  113. stop)
  114. echo "Stopping $DESC $NAME..."
  115. do_stop
  116. case "$?" in
  117. 0|1) echo " Stopping $DESC $NAME succeeded" ;;
  118. *) echo " Stopping $DESC $NAME failed" ;;
  119. esac
  120. ;;
  121. restart|force-reload)
  122. #
  123. # If the "reload" option is implemented then remove the
  124. # 'force-reload' alias
  125. #
  126. echo "Restarting $DESC $NAME..."
  127. do_stop
  128. case "$?" in
  129. 0|1)
  130. do_start
  131. case "$?" in
  132. 0|1) echo " Restarting $DESC $NAME succeeded" ;;
  133. *) echo " Restarting $DESC $NAME failed: couldn't start $NAME" ;;
  134. esac
  135. ;;
  136. *)
  137. echo " Restarting $DESC $NAME failed: couldn't stop $NAME" ;;
  138. esac
  139. ;;
  140. *)
  141. echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2
  142. exit 3
  143. ;;
  144. esac
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement