Changeset 24808
- Timestamp:
- 2010-12-23T00:14:56+01:00 (7 years ago)
- Location:
- packages/utils/watchcat
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
packages/utils/watchcat/Makefile
r24696 r24808 35 35 $(INSTALL_DIR) $(1)/etc/init.d 36 36 $(INSTALL_BIN) ./files/initd_watchcat $(1)/etc/init.d/watchcat 37 $(INSTALL_DIR) $(1)/usr/bin 38 $(INSTALL_BIN) ./files/watchcat.sh $(1)/usr/bin/watchcat.sh 37 39 $(INSTALL_DIR) $(1)/etc/defaults 38 40 $(INSTALL_BIN) ./files/uci_defaults_watchcat $(1)/etc/defaults/50-watchcat -
packages/utils/watchcat/files/initd_watchcat
r24692 r24808 6 6 7 7 append_string() { 8 local varname="$1"; local actual="${!varname}"; local add="$2"; local separator="${3:- }" 8 local varname="$1"; local add="$2"; local separator="${3:- }"; local actual 9 eval "actual=\$$varname" 10 9 11 new="${actual:+$actual$separator}$add" 10 12 eval "$varname=\$new" 11 13 } 12 13 shutdown_now() {14 local forcedelay="$1"15 16 reboot &17 18 [ "$forcedelay" -ge 1 ] && {19 sleep $forcedelay20 21 echo b > /proc/sysrq-trigger # Will immediately reboot the system without syncing or unmounting your disks.22 }23 }24 25 watchcat_allways() {26 local period="$1"; local forcedelay="$2"27 28 sleep $period && shutdown_now "$forcedelay"29 }30 31 watchcat_ping() {32 local period="$1"; local forcedelay="$2"; local pinghosts="$3"; local pingperiod="$4"33 34 time=$(cat /proc/uptime) && time=${time%%.*}35 last=$time36 37 while true38 do39 sleep $pingperiod40 41 time=$(cat /proc/uptime) && time=${time%%.*}42 43 for host in "$pinghosts"44 do45 if ping -c 1 "$host" &> /dev/null46 then47 last=$time48 else49 diff=$((time-last))50 logger -p daemon.info -t "watchcat[$$]" "no internet connectivity for $diff seconds. Reseting when reaching $period"51 fi52 done53 54 diff=$((time-last))55 [ $diff -ge $period ] && shutdown_now "$forcedelay"56 57 done58 }59 14 60 15 timetoseconds() { … … 80 35 timetoseconds "$period" 81 36 period="$seconds" 82 37 [ "$period" -ge 1 ] \ 83 38 || append_string "error" "period is not set or not recognized" "; " 84 39 [ "$mode" = "allways" -o "$mode" = "ping" ] \ 85 40 || append_string "error" "mode must be 'allways' or 'ping'" "; " 86 41 [ -n "$pinghosts" -o "$mode" = "allways" ] \ 87 42 || append_string "error" "pinghosts must be set in 'ping' mode" "; " 88 43 timetoseconds "$pingperiod" 89 44 pingperiod="$seconds" 90 [ "$pingperiod" -l "$period" -o "$mode" = "allways" ] \45 [ "$pingperiod" -lt "$period" -o "$mode" = "allways" ] \ 91 46 || append_string "error" "pingperiod is not recognized" "; " 92 47 [ "$forcedelay" -ge 0 ] \ … … 97 52 if [ "$mode" = "allways" ] 98 53 then 99 watchcat_allways "$period" "$forcedelay" & 54 /usr/bin/watchcat.sh "allways" "$period" "$forcedelay" & 55 logger -p user.info -t "wathchat" "started task (mode=$mode;period=$period;forcedelay=$forcedelay)" 100 56 else 101 watchcat_ping "$period" "$forcedelay" "$pinghosts" "$pingperiod" & 57 /usr/bin/watchcat.sh "period" "$period" "$forcedelay" "$pinghosts" "$pingperiod" & 58 logger -p user.info -t "wathchat" "started task (mode=$mode;pinghosts=$pinghosts;pingperiod=$pingperiod;forcedelay=$forcedelay)" 102 59 fi 103 60 104 echo $! >> "$PIDFILE".pids 105 106 logger -p user.info -t "sshtunnel" "started tunnels to $server (pid=$!;retrydelay=$retrydelay)" 61 echo $! >> "${PIDFILE}.pids" 107 62 } 108 63 109 64 stop() { 110 if [ -f "$PIDFILE".pids ] 111 then 112 logger -p user.info -t "watchcat" "stopping all reboot programs" 113 114 while read pid 115 do 116 kill $pid 117 done < "$PIDFILE".pids 65 if [ -f "${PIDFILE}.pids" ] 66 then 67 logger -p user.info -t "watchcat" "stopping all tasks" 118 68 119 rm "$PIDFILE".pids 69 while read pid 70 do 71 kill "$pid" 72 done < "${PIDFILE}.pids" 120 73 121 logger -p user.info -t "watchcat" "all reboot programs stopped" 122 else 123 logger -p user.info -t "watchcat" "no reboot programs running" 124 fi 74 rm "${PIDFILE}.pids" 75 76 logger -p user.info -t "watchcat" "all tasks stopped" 77 else 78 logger -p user.info -t "watchcat" "no tasks running" 79 fi 125 80 } 126 81 127 82 start() { 128 [ -f "$ PIDFILE".pids] && stop129 83 [ -f "${PIDFILE}.pids" ] && stop 84 130 85 config_load system 131 86 if [ -n "$(uci show system.@watchcat[0])" ] # at least one watchcat section exists 132 then 133 logger -p user.info -t "watchcat" "starting all reboot programs"87 then 88 logger -p user.info -t "watchcat" "starting all tasks" 134 89 config_foreach load_watchcat watchcat 135 logger -p user.info -t "watchcat" "all reboot programs started"90 logger -p user.info -t "watchcat" "all tasks started" 136 91 else 137 logger -p user.info -t "watchcat" "no reboot programs defined"92 logger -p user.info -t "watchcat" "no tasks defined" 138 93 fi 139 94 }
Note: See TracChangeset
for help on using the changeset viewer.