Advertisement
Guest User

Untitled

a guest
Mar 6th, 2015
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.00 KB | None | 0 0
  1. #!/bin/sh
  2. ### BEGIN INIT INFO
  3. # Provides:
  4. # Required-Start: $remote_fs $syslog
  5. # Required-Stop: $remote_fs $syslog
  6. # Default-Start: 2 3 4 5
  7. # Default-Stop: 0 1 6
  8. # Short-Description: Start daemon at boot time
  9. # Description: Enable service provided by daemon.
  10. ### END INIT INFO
  11.  
  12. dir="/usr/share/games/quake"
  13. user="bud"
  14. cmd="darkplaces-server -basedir /usr/share/games/quake +exec debian_server.cfg"
  15.  
  16. name=`basename $0`
  17. pid_file="/var/run/$name.pid"
  18. stdout_log="/var/log/$name.log"
  19. stderr_log="/var/log/$name.err"
  20.  
  21. get_pid() {
  22. cat "$pid_file"
  23. }
  24.  
  25. is_running() {
  26. [ -f "$pid_file" ] && ps `get_pid` > /dev/null 2>&1
  27. }
  28.  
  29. case "$1" in
  30. start)
  31. if is_running; then
  32. echo "Already started"
  33. else
  34. echo "Starting $name"
  35. cd "$dir"
  36. sudo -u "$user" $cmd >> "$stdout_log" 2>> "$stderr_log" &
  37. echo $! > "$pid_file"
  38. if ! is_running; then
  39. echo "Unable to start, see $stdout_log and $stderr_log"
  40. exit 1
  41. fi
  42. fi
  43. ;;
  44. stop)
  45. if is_running; then
  46. echo -n "Stopping $name.."
  47. kill `get_pid`
  48. for i in {1..10}
  49. do
  50. if ! is_running; then
  51. break
  52. fi
  53.  
  54. echo -n "."
  55. sleep 1
  56. done
  57. echo
  58.  
  59. if is_running; then
  60. echo "Not stopped; may still be shutting down or shutdown may have failed"
  61. exit 1
  62. else
  63. echo "Stopped"
  64. if [ -f "$pid_file" ]; then
  65. rm "$pid_file"
  66. fi
  67. fi
  68. else
  69. echo "Not running"
  70. fi
  71. ;;
  72. restart)
  73. $0 stop
  74. if is_running; then
  75. echo "Unable to stop, will not attempt to start"
  76. exit 1
  77. fi
  78. $0 start
  79. ;;
  80. status)
  81. if is_running; then
  82. echo "Running"
  83. else
  84. echo "Stopped"
  85. exit 1
  86. fi
  87. ;;
  88. *)
  89. echo "Usage: $0 {start|stop|restart|status}"
  90. exit 1
  91. ;;
  92. esac
  93.  
  94. exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement