server.sh 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #!/bin/bash
  2. #
  3. # Description: server
  4. #
  5. # Source function library
  6. PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
  7. NAME=SERVER_NAME
  8. USER=SERVER_USER
  9. DAEMON=SERVER_DAEMON
  10. PROCESS=/var/run/$NAME.pid
  11. SERVERPATH=SERVER_PATH
  12. if [ ! -f "$DAEMON" ]; then
  13. echo "$DAEMON not found"
  14. exit
  15. fi
  16. # Start the server
  17. start (){
  18. # Check serve's status
  19. start-stop-daemon --status --pidfile=$PROCESS
  20. if [ $? == 0 ]; then
  21. echo "$NAME is already running"
  22. exit
  23. fi
  24. start-stop-daemon --start --make-pidfile --background --pidfile=$PROCESS --chuid=$USER --chdir=$SERVERPATH --exec=$DAEMON
  25. test $? -ne 0 || echo "$NAME start successful, pid(`cat $PROCESS`)"
  26. }
  27. # Stop the server
  28. stop (){
  29. # Check serve's status
  30. start-stop-daemon --status --pidfile=$PROCESS
  31. if [ $? != 0 ]; then
  32. echo "$NAME is not running"
  33. fi
  34. start-stop-daemon --stop --pidfile=$PROCESS
  35. test $? -ne 0 || echo "$NAME stop successful"
  36. }
  37. # Return the status of the server
  38. status (){
  39. start-stop-daemon --status --pidfile=$PROCESS
  40. if [ $? == 0 ]; then
  41. echo "$NAME is running, pid(`cat $PROCESS`)"
  42. else
  43. echo "$NAME is not running"
  44. fi
  45. }
  46. # Restart the server
  47. restart (){
  48. stop
  49. start
  50. }
  51. usage (){
  52. echo "Usage: start|stop|restart|status"
  53. }
  54. case $1 in
  55. start)
  56. start
  57. ;;
  58. stop)
  59. stop
  60. ;;
  61. restart)
  62. restart
  63. ;;
  64. status)
  65. status
  66. ;;
  67. *)
  68. usage
  69. exit 1
  70. ;;
  71. esac