Share Pastebin
Guest
Public paste!

Untitled

By: a guest | Mar 20th, 2010 | Syntax: None | Size: 2.95 KB | Hits: 43 | Expires: Never
Copy text to clipboard
  1. #!/bin/bash
  2. # Set the path to the scripts folder (you should not need to modify this.)
  3. confdir=.
  4.  
  5. # Name of configuration file to use (you should not need to modify this.)
  6. conffile=hlstats.conf
  7. # Filename of daemon to use (you should not need to modify this.)
  8. daemonfile=hlstats.pl
  9. # Set where you want to log to (you should not need to modify this.)
  10. logdir=logs
  11. # Set the format for the log file
  12. logfile=hlstats`date +_%Y%m%d_%H-%M-%S`
  13. # Set where to store PID files
  14. piddir=${confdir}
  15.  
  16. # verify that you have write access to the directories
  17. if [ ! -w ${confdir} ]; then
  18.         echo "you need write access to ${confdir}"
  19.         exit 1
  20. fi
  21.  
  22. # verify that we can see the daemon file
  23. if [ ! -f ${confdir}/${daemonfile} ]; then
  24.     echo "Can't see the daemon.  (${daemonfile})"
  25.     exit 1
  26. fi
  27.  
  28. # verify that you have a logs directory
  29. if [ ! -d ${confdir}/${logdir} ]; then
  30.         mkdir ${confdir}/${logdir}
  31. fi
  32.  
  33. if [ ! -w ${confdir}/${logdir} ]; then
  34.         echo "you need write access to ${confdir}/${logdir}"
  35.         exit 1
  36. fi
  37.  
  38. # Grab the current directory so we can put the user back there!
  39. origdir=`pwd`
  40.  
  41. # Move into the configured directory
  42. cd ${confdir}
  43.  
  44. case "$1" in
  45.         start)
  46.                 # verify that we have a .conf file
  47.                 if [ ! -f ${conffile} ]; then
  48.                         echo "You're missing your configuration file.  (${conffile})"
  49.                         exit 1
  50.                 fi  
  51.    
  52.                 echo "Starting HLstatsX:CE Dust-2-DM";
  53.                 if [ -f ${piddir}/hlstats.pid ]; then
  54.                         kill -0 `cat ${piddir}/hlstats.pid` >/dev/null 2>&1
  55.                         if [ "$?" == "0" ]; then
  56.                                 echo "HLstatsX:CE already running!"
  57.                         else
  58.                                 rm -rf ${piddir}/hlstats.pid
  59.                                 ./${daemonfile} --configfile=${conffile} > ${logdir}/${logfile} 2>&1 &
  60.                                 echo $! >${piddir}/hlstats.pid
  61.                                 echo "PID file created"
  62.                                 echo "Started successfully"
  63.                         fi
  64.                 else
  65.                         ./${daemonfile} --configfile=${conffile} > ${logdir}/${logfile} 2>&1 &
  66.                         echo $! >${piddir}/hlstats.pid
  67.                         echo "PID file created"
  68.                         echo "Started successfully"
  69.                 fi
  70.         ;;
  71.        
  72.         stop)
  73.                 echo "Stopping HLstatsX:CE Dust-2-DM"
  74.                 kill -9 `cat ${piddir}/hlstats.pid` >/dev/null 2>&1
  75.                 if [ "$?" == "0" ]; then
  76.                         rm -rf ${piddir}/hlstats.pid
  77.                         echo "Stopped successfully"
  78.                 else
  79.                         echo "No HLstatsX:CE running!"
  80.                 fi
  81.         ;;
  82.        
  83.         restart)
  84.                 echo "Restarting HLstatsX:CE Dust-2-DM"
  85.                 kill -9 `cat ${piddir}/hlstats.pid` >/dev/null 2>&1
  86.        
  87.                 if [ "$?" == "0" ]; then
  88.                         rm -rf ${piddir}/hlstats.pid
  89.                         ./${daemonfile} --configfile=${conffile} > ${logdir}/${logfile} 2>&1 &
  90.                         echo $! >${piddir}/hlstats.pid
  91.                         echo "PID file created"
  92.                         echo "Restarted successfully"
  93.                 else    
  94.                         echo "HLstatsX:CE"
  95.                         if [ -f ${piddir}/hlstats.pid ]; then
  96.                                 rm -rf ${piddir}/hlstats.pid
  97.                         fi
  98.                         ./${daemonfile} --configfile=${conffile} > ${logdir}/${logfile} 2>&1 &
  99.                         echo $! >${piddir}/hlstats.pid
  100.                         echo "PID file created"
  101.                         echo "Started successfully"
  102.                 fi
  103.         ;;
  104.        
  105.    *)
  106.                 echo "Usage: ./run_hlstats [ start | stop | restart ]"
  107.         ;;
  108. esac
  109.  
  110. # Return to the original directory
  111. cd ${origdir}
  112. exit 0