crond.sh 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #!/bin/bash
  2. pidPath="../runtime/crond.pid"
  3. phpbin="/alidata/server/php/bin/php"
  4. logFile="../runtime/crond.log"
  5. cd /alidata/www/zhipuzi/cysystem/scripts/
  6. #crond server
  7. stop() {
  8. if [ -f $pidPath ]; then
  9. pid=`cat $pidPath`
  10. echo "stop crond server, pid="$pid"..."
  11. check_crond_exist
  12. pidIsExits=$?
  13. if [ $pidIsExits -eq 1 ]; then
  14. kill $pid
  15. else
  16. echo "crond server not exist."
  17. rm -f $pidPath
  18. fi
  19. try=0
  20. while test $try -lt 60; do
  21. if [ ! -f "$pidPath" ]; then
  22. try=''
  23. break
  24. fi
  25. echo -n
  26. try=`expr $try + 1`
  27. sleep 1
  28. done
  29. echo "stop crond ok."
  30. fi
  31. }
  32. #启动crond server
  33. start() {
  34. check_crond_exist
  35. pidIsExits=$?
  36. if [ $pidIsExits -eq 1 ]; then
  37. echo "crond server had running..."
  38. else
  39. echo "start crond server..."
  40. cmd=$phpbin" crond.php -d"
  41. $cmd &> $logFile
  42. fi
  43. }
  44. #检测crond进程是否存在
  45. check_crond_exist() {
  46. if [ ! -f $pidPath ]; then
  47. return 0
  48. fi
  49. pid=`cat $pidPath`
  50. pids=`ps aux | grep crond.php | grep -v grep | awk '{print $2}'`
  51. pidIsExits=0;
  52. for i in ${pids[@]}
  53. do
  54. if [ "$i" -eq "$pid" ]; then
  55. pidIsExits=1
  56. break
  57. fi
  58. done
  59. return $pidIsExits
  60. }
  61. case "$1" in
  62. start)
  63. start
  64. ;;
  65. stop)
  66. stop
  67. ;;
  68. *)
  69. echo $"Usage: crond.sh {start|stop|help}"
  70. exit 1
  71. esac