server.sh 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. if [ ! -f "$DAEMON" ]; then
  12. echo "$DAEMON not found"
  13. exit
  14. fi
  15. # Start the server
  16. start (){
  17. # Check serve's status
  18. start-stop-daemon --status --pidfile=$PROCESS
  19. if [ $? == 0 ]; then
  20. echo "$NAME is already running"
  21. exit
  22. fi
  23. start-stop-daemon --start --make-pidfile --background --pidfile=$PROCESS --user=$USER --exec=$DAEMON
  24. echo "$NAME start successful, pid(`cat $PROCESS`)"
  25. }
  26. # Stop the server
  27. stop (){
  28. # Check serve's status
  29. start-stop-daemon --status --pidfile=$PROCESS
  30. if [ $? != 0 ]; then
  31. echo "$NAME is not running"
  32. fi
  33. start-stop-daemon --stop --pidfile=$PROCESS
  34. echo "$NAME stop successful"
  35. }
  36. # Return the status of the server
  37. status (){
  38. start-stop-daemon --status --pidfile=$PROCESS
  39. if [ $? == 0 ]; then
  40. echo "$NAME is running, pid(`cat $PROCESS`)"
  41. else
  42. echo "$NAME is not running"
  43. fi
  44. }
  45. # Restart the server
  46. restart (){
  47. stop
  48. start
  49. }
  50. usage (){
  51. echo "Usage: start|stop|restart|status"
  52. }
  53. case $1 in
  54. start)
  55. start
  56. ;;
  57. stop)
  58. stop
  59. ;;
  60. restart)
  61. restart
  62. ;;
  63. status)
  64. status
  65. ;;
  66. *)
  67. usage
  68. exit 1
  69. ;;
  70. esac