openwrt-daemon.sh 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. #!/bin/bash /etc/rc.common
  2. #Created by oycol<[email protected]>
  3. EXTRA_COMMANDS="status"
  4. EXTRA_HELP=" status Check service is running"
  5. START=99
  6. LOG_FILE="/tmp/netclient.logs"
  7. start() {
  8. if [ ! -f "${LOG_FILE}" ];then
  9. touch "${LOG_FILE}"
  10. fi
  11. local PIDS=($(ps -e|grep "netclient checkin -n all"|grep -v grep|awk '{print $1}'))
  12. if [ ${PIDS} ];then
  13. echo "service is running"
  14. return
  15. fi
  16. bash -c "while [ 1 ]; do /etc/netclient/netclient checkin -n all >> ${LOG_FILE} 2>&1;sleep 15;\
  17. if [ $(ls -l ${LOG_FILE}|awk '{print $5}') -gt 10240000 ];then tar zcf "${LOG_FILE}.tar" -C / "tmp/netclient.logs" && > ${LOG_FILE};fi;done &"
  18. echo "start"
  19. }
  20. stop() {
  21. local PIDS=($(ps -e|grep "netclient checkin -n all"|grep -v grep|awk '{print $1}'))
  22. for i in "${PIDS[@]}"; do
  23. kill $i
  24. done
  25. echo "stop"
  26. }
  27. status() {
  28. local PIDS=($(ps -e|grep "netclient checkin -n all"|grep -v grep|awk '{print $1}'))
  29. if [ ${PIDS} ];then
  30. echo -e "netclient[${PIDS}] is running \n"
  31. else
  32. echo -e "netclient is not running \n"
  33. fi
  34. }