openwrt-daemon.sh 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #!/bin/sh /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. mkdir -p /etc/netclient/config
  9. mkdir -p /etc/systemd/system
  10. if [ ! -f "${LOG_FILE}" ];then
  11. touch "${LOG_FILE}"
  12. fi
  13. local PID=$(ps|grep "netclient daemon"|grep -v grep|awk '{print $1}')
  14. if [ "${PID}" ];then
  15. echo "service is running"
  16. return
  17. fi
  18. /bin/sh -c "while [ 1 ]; do netclient daemon >> ${LOG_FILE} 2>&1;sleep 15;\
  19. if [ $(ls -l ${LOG_FILE}|awk '{print $5}') -gt 10240000 ];then tar zcf "${LOG_FILE}.tar" -C / "tmp/netclient.logs" && > $LOG_FILE;fi;done &"
  20. echo "start"
  21. }
  22. stop() {
  23. local PID=$(ps|grep "netclient daemon"|grep -v grep|awk '{print $1}')
  24. if [ "${PID}" ];then
  25. kill ${PID}
  26. fi
  27. echo "stop"
  28. }
  29. status() {
  30. local PID=$(ps|grep "netclient daemon"|grep -v grep|awk '{print $1}')
  31. if [ "${PID}" ];then
  32. echo -e "netclient[${PID}] is running \n"
  33. else
  34. echo -e "netclient is not running \n"
  35. fi
  36. }