Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

uccl

By: a guest on Jan 31st, 2012  |  syntax: Bash  |  size: 2.80 KB  |  views: 266  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #!/bin/bash
  2.  
  3. . /lib/lsb/init-functions
  4.  
  5. GAME_DIR=/srv/games/RVS
  6. NAME_OF_THE_GAME="Ravenshield"
  7.  
  8. CHUSER=games
  9. CHGROUP=games
  10.  
  11. SHELL=/usr/bin/wine
  12.  
  13. NAME_OF_THE_GAME_INSTANCE="$NAME_OF_THE_GAME($2)"
  14. GAME_EXECUTABLES_DIR=$GAME_DIR/System
  15. GAME_EXECUTABLE_FILENAME=UCC.exe
  16. GAME_EXECUTABLE_FULLPATH=$GAME_EXECUTABLES_DIR/$GAME_EXECUTABLE_FILENAME
  17.  
  18. PROFILES=/etc/uccl/profiles
  19. TEMPLATEPROFILES=$PROFILES/templates
  20. SERVERPROFILES=$PROFILES/game-servers
  21.  
  22. LOGFILE=/dev/null
  23.  
  24. RUNDIR=/var/run
  25. PIDDIR=$RUNDIR/ucc-servers
  26. PIDFILE=$PIDDIR/$2.pid
  27.  
  28. STARTER="$SHELL $GAME_EXECUTABLE_FULLPATH"
  29. EXTRA_OPTS="server servercfg=$SERVERPROFILES/$2.ini"
  30. #> $LOGFILE 2>&1
  31.  
  32. ## FOR DEBUGGING SCRIPT
  33.  
  34. echo 'Exccutables dir:' $GAME_EXECUTABLES_DIR
  35. echo 'Exccutable filename:' $GAME_EXECUTABLE_FILENAME
  36. echo 'Executable fullpath:' $GAME_EXECUTABLE_FULLPATH
  37. echo 'Starter:' $STARTER
  38. echo 'PID dir:' $PIDDIR
  39. echo 'PID file:' $PIDFILE
  40. echo
  41.  
  42. check_pid_dir()
  43. {
  44.     if [ -d "$PIDDIR" ];
  45.     then
  46.         false
  47.     else
  48.         mkdir $PIDDIR && chown $CHUSER:$CHGROUP $PIDDIR
  49.     fi
  50. }
  51.  
  52. start()
  53. {
  54.     start-stop-daemon --start --quiet --pidfile $PIDFILE --background --chdir $GAME_EXECUTABLES_DIR --chuid $CHUSER:$CHGROUP --name $GAME_EXECUTABLE_FILENAME --startas $STARTER -- $EXTRA_OPTS
  55. }
  56.  
  57. debug()
  58. {
  59.     start-stop-daemon --start --verbose --chdir $GAME_EXECUTABLES_DIR --name $GAME_EXECUTABLE_FILENAME --startas $STARTER -- $EXTRA_OPTS
  60. }
  61.  
  62. stop()
  63. {
  64.     start-stop-daemon --stop --quiet --pidfile $PIDFILE --name $GAME_EXECUTABLE_FILENAME
  65. }
  66.  
  67.  
  68. case "$1" in
  69. start)  log_daemon_msg "Starting game server" $NAME_OF_THE_GAME_INSTANCE
  70.         check_pid_dir
  71.         start
  72.         log_end_msg $?
  73.         ;;
  74. debug)  log_daemon_msg "Starting game server in debug mode" $NAME_OF_THE_GAME_INSTANCE
  75.         echo
  76.         echo
  77.         debug
  78.         log_end_msg $?
  79.         ;;
  80. stop)   log_daemon_msg "Stopping game server" $NAME_OF_THE_GAME_INSTANCE
  81.         stop
  82.         log_end_msg $?
  83.         ;;
  84. restart) log_daemon_msg "Restarting game server" $NAME_OF_THE_GAME_INSTANCE
  85.         stop
  86.         start
  87. $RVSEXECUTABLES/ucc.exe server serverini=$SERVERPROFILES/$2.ini > $LOGFILE 2>&1 -- $LSBNAMES $EXTRA_OPTS
  88.         log_end_msg $?
  89.         ;;
  90. status)
  91.        log_action_begin_msg "Checking $NAME_OF_THE_GAME game server"
  92.        if pidofproc -p "$PIDFILE" >/dev/null; then
  93.             log_action_end_msg 0 "running"
  94.             exit 0
  95.        else
  96.            if [ -e "$PIDFILE" ]; then
  97.                 log_action_end_msg 1 "failed to start"
  98.                 exit 1
  99.            else
  100.                 log_action_end_msg 0 "not running"
  101.                 exit 3
  102.            fi
  103.        fi
  104.          ;;
  105. *)      log_action_msg "Usage: /etc/init.d/cron {start|stop|status|restart} {ServerProfile}"
  106.         exit 2
  107.         ;;
  108. esac
  109.  
  110. exit 0