Advertisement
dsonbill

DMPServer Linux Daemon

Sep 9th, 2014
996
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 3.26 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # Config
  4. . /etc/dmpserver/dmpserver.cfg
  5.  
  6. # Lib
  7. . /var/lib/dmpserver/dmpbashlib
  8.  
  9.  
  10. # Check for root
  11. rootCheck
  12.  
  13.  
  14. start(){
  15.     fileExistTest $DMPDIR/$1/DMPServer.exe
  16.     if [ $RETVAL == "False" ] ; then
  17.         echo "FATAL: COULD NOT LOCATE THE DMPSERVER ENVIRONMENT!"
  18.         exit 2
  19.     fi
  20.  
  21.     echo -n "Starting $SERVICENAME $1: "
  22.    
  23.     if [ ! -f $LOCKFILE.$1 ];
  24.     then
  25.         su $user -s $shell <<EOF
  26.         screen -S $1 -d -m mono $DMPDIR/$1/DMPServer.exe
  27. EOF
  28.         touch $LOCKFILE.$1
  29.            
  30.         echo -e "${formatDone} SUCCESS ${formatEnd}"
  31.     else
  32.         echo -e "${formatFail} FAILURE ${formatEnd}"
  33.        
  34.         echo "DMPSERVER IS ALREADY RUNNING, OR ROUGE LOCK FILE"
  35.         exit 2
  36.     fi
  37. }
  38.  
  39. stop(){
  40.     echo -n "Shutting down $SERVICENAME $1: "
  41.    
  42.     if [ -f $LOCKFILE.$1 ];
  43.     then
  44.         case "$2" in
  45.             -f) dmpcmd $1 shutdown -f ;;
  46.             *) dmpcmd $1 shutdown ;;
  47.         esac
  48.        
  49.         rm -f $LOCKFILE.$1
  50.        
  51.         echo -e "${formatDone} SUCCESS ${formatEnd}"
  52.     else
  53.         echo -e "${formatFail} FAILURE ${formatEnd}"
  54.        
  55.         echo "DMPSERVER IS NOT RUNNING OR MISSING LOCK FILE"
  56.         exit 2
  57.     fi
  58. }
  59.  
  60. restart(){
  61.     echo -n "Restarting $SERVICENAME $1: "
  62.     if [ -f $LOCKFILE.$1 ];
  63.     then
  64.         case "$2" in
  65.             -f) dmpcmd $1 restart -f ;;
  66.             *) dmpcmd $1 restart
  67.         esac
  68.     fi
  69.     echo -e "${formatFail} DONE ${formatEnd}"
  70. }
  71.  
  72.  
  73. status(){
  74.     echo -n "Status of $SERVICENAME $1: "
  75.     if [ -f $LOCKFILE.$1 ];
  76.     then
  77.         echo -e "${formatDone} RUNNING ${formatEnd}"
  78.         exit 1
  79.     else
  80.         echo -e "${formatFail} NOT RUNNING ${formatEnd}"
  81.         exit 0
  82.     fi
  83. }
  84.  
  85. update(){
  86.     dmpbashup
  87. }
  88.  
  89. # Print usage if no arguments
  90. if [ $# -eq 0 ] ; then
  91.     echo "Usage: $0 [server name] {start|stop|status|restart|stop-fast|restart-fast}"
  92. fi
  93.  
  94. # Manipulate default server when only one arg is used
  95. if [ $# -eq 1 ] ; then
  96.     case "$1" in
  97.         start) start default  ;;
  98.        
  99.         stop) stop default  ;;
  100.        
  101.         stop-fast) stop default -f  ;;
  102.        
  103.         restart) restart default  ;;
  104.        
  105.         restart-fast) restart default -f  ;;
  106.        
  107.         status) status default  ;;
  108.            
  109.         update)
  110.             update
  111.             echo "Update successful! Please restart DMPServer for changes to take effect."
  112.             ;;
  113.        
  114.         *)
  115.             echo "Usage: $0 [server name] {start|stop|status|restart|stop-fast|restart-fast}"
  116.             exit 3
  117.             ;;
  118.     esac
  119. fi
  120.  
  121.  
  122. # Otherwise, manipulate the named server
  123. if [ $# -eq 2 ] ; then
  124.     case "$2" in
  125.         start) start $1  ;;
  126.        
  127.         stop) stop $1  ;;
  128.        
  129.         stop-fast) stop $1 -f  ;;
  130.        
  131.         status) status $1  ;;
  132.        
  133.         restart) restart $1  ;;
  134.            
  135.         restart-fast) restart $1 -f  ;;
  136.            
  137.         update)
  138.             update
  139.             echo "Update successful! Please restart DMPServer for changes to take effect."
  140.             ;;
  141.        
  142.         *)
  143.             echo "Usage: $0 [server name] {start|stop|status|restart|stop-fast|restart-fast}"
  144.             exit 3
  145.             ;;
  146.     esac
  147. fi
  148.  
  149.  
  150.  
  151.  
  152. exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement