Advertisement
Guest User

Untitled

a guest
Jun 24th, 2018
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.51 KB | None | 0 0
  1. kboxv2:/etc/init.d# cat teamspeak-server
  2. #!/bin/sh
  3. ### BEGIN INIT INFO
  4. # Provides: teamspeak-server
  5. # Required-Start: $local_fs $network
  6. # Required-Stop: $local_fs $network
  7. # Default-Start: 2 3 4 5
  8. # Default-Stop: 0 1 6
  9. # Short-Description: TeamSpeak server
  10. # Description: VoIP chat for online gaming
  11. ### END INIT INFO
  12.  
  13. # Author: Adam Cécile (Le_Vert) <gandalf@le-vert.net>
  14. # Distributed under terms of GNU General Public License.
  15.  
  16. PATH=/usr/sbin:/usr/bin:/sbin:/bin
  17. DESC="VoIP chat for online gaming"
  18. NAME=teamspeak-server
  19. DAEMON=/usr/bin/teamspeak-server
  20. PIDFILE=/var/run/$NAME.pid
  21. SCRIPTNAME=/etc/init.d/$NAME
  22. GETPASSWORDS=/usr/lib/teamspeak-server/getpasswords
  23.  
  24. # Read configuration variable file if it is present
  25. [ -r /etc/default/$NAME ] && . /etc/default/$NAME
  26.  
  27. DAEMON_ARGS=" \
  28. -ini=$CONF \
  29. -log=$LOG \
  30. -db=$SQLDB \
  31. -sql=$SQLSKEL \
  32. -badnames=$BADNAMES \
  33. -httpdocs=$HTTPDOCS \
  34. -tcpquerydocs=$TCPQUERYDOCS \
  35. -pid=$PIDFILE \
  36. "
  37.  
  38. # Exit if the package is not installed
  39. [ -x "$DAEMON" ] || exit 0
  40.  
  41. # Exit if not ENABLE=1
  42. [ $ENABLED -eq 1 ] || exit 0
  43.  
  44. # Load the VERBOSE setting and other rcS variables
  45. [ -f /etc/default/rcS ] && . /etc/default/rcS
  46.  
  47. # Define LSB log_* functions.
  48. # Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
  49. . /lib/lsb/init-functions
  50.  
  51. # Function that starts the daemon/service
  52. do_start()
  53. {
  54. # Return
  55. # 0 if daemon has been started
  56. # 1 if daemon was already running
  57. # 2 if daemon could not be started
  58.  
  59. # Create the log file and make it unreadable for all (contain srv admin passwd)
  60. touch $LOG; chown teamspeak-server:adm $LOG; chmod 0640 $LOG
  61.  
  62. # Create the pid file and make it writable for teamspeak-sever
  63. touch $PIDFILE; chown teamspeak-server:root $PIDFILE; chmod 0644 $PIDFILE
  64.  
  65. start-stop-daemon --start \
  66. --quiet \
  67. --pidfile $PIDFILE \
  68. --exec $DAEMON \
  69. --test > /dev/null \
  70. || return 1
  71.  
  72. start-stop-daemon --start \
  73. --quiet \
  74. --pidfile $PIDFILE \
  75. --chuid teamspeak-server:teamspeak-server \
  76. --exec $DAEMON -- \
  77. $DAEMON_ARGS >/dev/null 2>&1\
  78. || return 2
  79.  
  80. # Run a script that will extract passwords from the log file and store them somewhere
  81. [ -r $LOG ] && $GETPASSWORDS $LOG
  82.  
  83. }
  84.  
  85. # Function that stops the daemon/service
  86. do_stop()
  87. {
  88. # Return
  89. # 0 if daemon has been stopped
  90. # 1 if daemon was already stopped
  91. # 2 if daemon could not be stopped
  92. # other if a failure occurred
  93.  
  94. start-stop-daemon --stop \
  95. --quiet \
  96. --user teamspeak-server \
  97. --retry=TERM/30/KILL/5 \
  98. --pidfile $PIDFILE
  99.  
  100. RETVAL=$?
  101. # Delete pidfile when exit.
  102. rm -f $PIDFILE
  103. return "$RETVAL"
  104. }
  105.  
  106. case "$1" in
  107. start)
  108. [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
  109. do_start
  110. case "$?" in
  111. 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
  112. 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
  113. esac
  114. ;;
  115. stop)
  116. [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
  117. do_stop
  118. case "$?" in
  119. 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
  120. 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
  121. esac
  122. ;;
  123. status)
  124. [ -e $PIDFILE ] && echo "$NAME seems to be running with pid: `cat $PIDFILE`." \
  125. || echo "$NAME is not running."
  126. ;;
  127. restart|force-reload)
  128. log_daemon_msg "Restarting $DESC" "$NAME"
  129. do_stop
  130. case "$?" in
  131. 0|1)
  132. do_start
  133. case "$?" in
  134. 0) log_end_msg 0 ;;
  135. 1) log_end_msg 1 ;; # Old process is still running
  136. *) log_end_msg 1 ;; # Failed to start
  137. esac
  138. ;;
  139. *)
  140. # Failed to stop
  141. log_end_msg 1
  142. ;;
  143. esac
  144. ;;
  145. *)
  146. echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
  147. exit 3
  148. ;;
  149. esac
  150.  
  151. :
  152. kboxv2:/etc/init.d#
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement