diff --git a/scripts/openwrt-daemon.sh b/scripts/openwrt-daemon.sh index 4c74fa0f..7f0e0499 100644 --- a/scripts/openwrt-daemon.sh +++ b/scripts/openwrt-daemon.sh @@ -1,38 +1,43 @@ -#!/bin/bash /etc/rc.common +#!/bin/sh /etc/rc.common #Created by oycol EXTRA_COMMANDS="status" -EXTRA_HELP=" status Check service is running" +EXTRA_HELP=" status Check service is running" START=99 LOG_FILE="/tmp/netclient.logs" start() { + mkdir -p /etc/netclient/config + mkdir -p /etc/systemd/system + if [ ! -f "${LOG_FILE}" ];then touch "${LOG_FILE}" fi - local PIDS=($(ps -e|grep "netclient checkin -n all"|grep -v grep|awk '{print $1}')) - if [ ${PIDS} ];then + + local PID=$(ps|grep "netclient daemon"|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 &" + /bin/sh -c "while [ 1 ]; do netclient daemon >> ${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 PIDS=($(ps -e|grep "netclient checkin -n all"|grep -v grep|awk '{print $1}')) - for i in "${PIDS[@]}"; do - kill $i - done + local PID=$(ps|grep "netclient daemon"|grep -v grep|awk '{print $1}') + if [ "${PID}" ];then + kill ${PID} + fi echo "stop" } status() { - local PIDS=($(ps -e|grep "netclient checkin -n all"|grep -v grep|awk '{print $1}')) - if [ ${PIDS} ];then - echo -e "netclient[${PIDS}] is running \n" + local PID=$(ps|grep "netclient daemon"|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