服务启动脚本模板

  1. #!/bin/bash
  2. # chkconfig: 345 99 99
  3. # description: this is a testsrv
  4. . /etc/init.d/functions
  5. lockfile=/var/lock/subsys/$0
  6. start(){
  7. if [ -e $lockfile ] ; then
  8. action "$0 is running"
  9. else
  10. touch $lockfile
  11. if [ "$?" -eq 0 ] ; then
  12. action "$0 start"
  13. else
  14. action "$0 failed" false
  15. fi
  16. fi
  17. }
  18. stop(){
  19. if [ -e $lockfile ] ; then
  20. rm -rf $lockfile
  21. if [ "$?" -eq 0 ] ; then
  22. action "$0 stop"
  23. else
  24. action "$0 stop failed" false
  25. fi
  26. else
  27. action "$0 is stoped"
  28. fi
  29. }
  30. restart(){
  31. start
  32. stop
  33. }
  34. status(){
  35. if [ -e $lockfile ] ; then
  36. action "$0 running"
  37. else
  38. action "$0 stoped"
  39. fi
  40. }
  41. usage(){
  42. echo "$0 {start|stop|status|restart}"
  43. }
  44. case $1 in
  45. start)
  46. start;;
  47. stop)
  48. stop;;
  49. restart)
  50. restart;;
  51. status)
  52. status;;
  53. *)
posted @ 2018-02-28 13:55  莫孟林  阅读(135)  评论(0编辑  收藏  举报