blog.sh 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #!/bin/sh
  2. # 设置hexo 项目路径
  3. BLOG_PATH=/data/hexo/blog
  4. #使用说明,用来提示输入参数
  5. usage() {
  6. echo "Usage: sh 执行脚本.sh [start|stop|restart|status] "
  7. exit 1
  8. }
  9. #检查程序是否在运行
  10. is_exist(){
  11. pid=`ps -ef|grep hexo|grep -v grep|awk '{print $2}' `
  12. #如果不存在返回1,存在返回0
  13. if [ -z "${pid}" ]; then
  14. return 1
  15. else
  16. return 0
  17. fi
  18. }
  19. #启动方法
  20. start(){
  21. is_exist
  22. if [ $? -eq "0" ]; then
  23. echo "hexo_blog is already running. pid=${pid} ."
  24. else
  25. cd $BLOG_PATH
  26. git pull
  27. sleep 5
  28. hexo clean
  29. sleep 1
  30. # nohup hexo server >hexo-blog.log 2>&1 &
  31. hexo g
  32. fi
  33. }
  34. #停止方法
  35. stop(){
  36. is_exist
  37. if [ $? -eq "0" ]; then
  38. kill -9 $pid
  39. else
  40. echo "hexo_blog is not running"
  41. fi
  42. }
  43. #输出运行状态
  44. status(){
  45. is_exist
  46. if [ $? -eq "0" ]; then
  47. echo "hexo_blog is running. Pid is ${pid}"
  48. else
  49. echo "hexo_blog is NOT running."
  50. fi
  51. }
  52. #重启
  53. restart(){
  54. stop
  55. start
  56. }
  57. #根据输入参数,选择执行对应方法,不输入则执行使用说明
  58. case "$1" in
  59. "start")
  60. start
  61. ;;
  62. "stop")
  63. stop
  64. ;;
  65. "status")
  66. status
  67. ;;
  68. "restart")
  69. restart
  70. ;;
  71. *)
  72. usage
  73. ;;
  74. esac