serverdaemon 851 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. #!/bin/sh
  2. # a daemon, start and monitor servers
  3. # 2013-09-27 09:28 created by niujiuru
  4. # 2026-01-05 13:40 updated by niujiuru
  5. . $(dirname $0)/set_env
  6. . $(dirname $0)/modules/funcs/functions.sh
  7. export_env
  8. INTERVAL=60
  9. pidfile="${APPRUNS_PATH}/serverdaemon.pid"
  10. if [ -f "$pidfile" ]; then
  11. pid=$(cat "$pidfile")
  12. kill -0 "$pid" 2>/dev/null && exit 0
  13. rm -f "$pidfile"
  14. fi
  15. mkdir -p "$(dirname "$pidfile")"
  16. echo $$ > "$pidfile"
  17. while true
  18. do
  19. if ! is_running "${APPBINS_PATH}/${YFKJ_SSHD}"
  20. then
  21. echo "starting ${YFKJ_SSHD}: ${APPBINS_PATH}/${YFKJ_SSHD} &"
  22. rm -rf ${APPRUNS_PATH}/*.lock
  23. ${APPBINS_PATH}/${YFKJ_SSHD} &
  24. fi
  25. if ! is_running "${APPBINS_PATH}/${APPNAME}"
  26. then
  27. echo "starting ${APPNAME}: ${APPBINS_PATH}/${APPNAME} &"
  28. rm -rf ${APPRUNS_PATH}/*.lock
  29. ${APPBINS_PATH}/${APPNAME} &
  30. fi
  31. sleep $INTERVAL
  32. done