Browse Source

openwrt: small fix with pids

oycol 3 years ago
parent
commit
9a3fa2d8f1
2 changed files with 49 additions and 7 deletions
  1. 39 0
      scripts/openwrt-daemon-2.sh
  2. 10 7
      scripts/openwrt-daemon.sh

+ 39 - 0
scripts/openwrt-daemon-2.sh

@@ -0,0 +1,39 @@
+#!/bin/sh /etc/rc.common
+#Created by oycol<[email protected]>
+
+EXTRA_COMMANDS="status"
+EXTRA_HELP="        status      Check service is running"
+START=99
+
+LOG_FILE="/tmp/netclient.logs"
+
+start() {
+  if [ ! -f "${LOG_FILE}" ];then
+      touch "${LOG_FILE}"
+  fi
+  local PID=$(ps -ef|grep "netclient checkin -n all"|grep -v grep|awk '{print $1}')
+  if [ "${PID}" ];then
+    echo "service is running"
+    return
+  fi
+  bash -c "while [ 1 ]; do /etc/netclient/netclient checkin -n all >> ${LOG_FILE} 2>&1;sleep 15;\
+           if [ $(ls -l ${LOG_FILE}|awk '{print $5}') -gt 10240000 ];then tar zcf "${LOG_FILE}.tar" -C / "tmp/netclient.logs"  && > $LOG_FILE;fi;done &"
+  echo "start"
+}
+
+stop() {
+  local PID=$(ps -ef|grep "netclient checkin -n all"|grep -v grep|awk '{print $1}')
+  if [ "${PID}" ];then
+    kill "${PID}"
+  fi
+  echo "stop"
+}
+
+status() {
+  local PID=$(ps -ef|grep "netclient checkin -n all"|grep -v grep|awk '{print $1}')
+  if [ "${PID}" ];then
+    echo -e "netclient[${PID}] is running \n"
+  else
+    echo -e "netclient is not running \n"
+  fi
+}

+ 10 - 7
scripts/openwrt-daemon.sh

@@ -1,20 +1,23 @@
 #!/bin/bash /etc/rc.common
-# Copyright (C) 2007 OpenWrt.org
+#Created by oycol<[email protected]>
+
 EXTRA_COMMANDS="status"
 EXTRA_HELP="        status  	Check service is running"
 START=99
 
-
 LOG_FILE="/tmp/netclient.logs"
 
 start() {
+  if [ ! -f "${LOG_FILE}" ];then
+      touch "${LOG_FILE}"
+  fi
   local PIDS=($(ps -ef|grep "netclient checkin -n all"|grep -v grep|awk '{print $1}'))
-  if [ $PIDS ];then
+  if [ ${PIDS} ];then
     echo "service is running"
     return
   fi
-  bash -c "while [ 1 ]; do /etc/netclient/netclient checkin -n all >> $LOG_FILE 2>&1;sleep 15;\
-           if [ $(ls -l $LOG_FILE|awk '{print $5}') -gt 10240000 ];then tar zcf "${LOG_FILE}.tar" -C / "tmp/netclient.logs"  && > $LOG_FILE;fi;done &"
+  bash -c "while [ 1 ]; do /etc/netclient/netclient checkin -n all >> ${LOG_FILE} 2>&1;sleep 15;\
+           if [ $(ls -l ${LOG_FILE}|awk '{print $5}') -gt 10240000 ];then tar zcf "${LOG_FILE}.tar" -C / "tmp/netclient.logs"  && > ${LOG_FILE};fi;done &"
   echo "start"
 }
 
@@ -28,8 +31,8 @@ stop() {
 
 status() {
   local PIDS=($(ps -ef|grep "netclient checkin -n all"|grep -v grep|awk '{print $1}'))
-  if [ $PIDS ];then
-    echo -e "netclient[$PIDS] is running \n"
+  if [ ${PIDS} ];then
+    echo -e "netclient[${PIDS}] is running \n"
   else
     echo -e "netclient is not running \n"
   fi