| 123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- #!/bin/sh
- # a daemon, start and monitor servers
- # 2013-09-27 09:28 created by niujiuru
- # 2026-01-05 13:40 updated by niujiuru
- # 2026-03-10 09:10 updated by niujiuru
- . "$(dirname "$0")/set_env"
- . "$(dirname "$0")/modules/funcs/functions.sh"
- export_env
- INTERVAL=60
- pidfile="${APPRUNS_PATH}/serverdaemon.pid"
- if [ -f "$pidfile" ]; then
- pid=$(cat "$pidfile" 2>/dev/null)
- if [ -n "$pid" ] && kill -0 "$pid" 2>/dev/null; then
- exit 0
- fi
- rm -f "$pidfile"
- fi
- mkdir -p "$(dirname "$pidfile")"
- echo $$ > "$pidfile"
- start_if_needed()
- {
- name="$1"
- path="${APPBINS_PATH}/${name}"
- lock="${APPRUNS_PATH}/${name}.lock"
- if ! is_running "$path"
- then
- rm -f "$lock"
- echo "starting $name: $path"
- "$path" &
- fi
- }
- while true
- do
- start_if_needed "${YFKJ_SSHD}" # 远程运维服务
- start_if_needed "${APPNAME}" # ㊣主应用程序
- sleep $INTERVAL
- done
|