Dirty fix to run on openwrt as init daemon

This commit is contained in:
Alexander Sorokin
2022-08-26 14:11:22 +03:00
committed by GitHub
parent c861f0f8b6
commit 04515aadaa

View File

@@ -1,4 +1,4 @@
#!/bin/bash /etc/rc.common #!/bin/sh /etc/rc.common
#Created by oycol<oycol527@outlook.com> #Created by oycol<oycol527@outlook.com>
EXTRA_COMMANDS="status" EXTRA_COMMANDS="status"
@@ -8,31 +8,36 @@ START=99
LOG_FILE="/tmp/netclient.logs" LOG_FILE="/tmp/netclient.logs"
start() { start() {
mkdir -p /etc/netclient/config
mkdir -p /etc/systemd/system
if [ ! -f "${LOG_FILE}" ];then if [ ! -f "${LOG_FILE}" ];then
touch "${LOG_FILE}" touch "${LOG_FILE}"
fi 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" echo "service is running"
return return
fi fi
bash -c "while [ 1 ]; do /etc/netclient/netclient checkin -n all >> ${LOG_FILE} 2>&1;sleep 15;\ /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 &" 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" echo "start"
} }
stop() { stop() {
local PIDS=($(ps -e|grep "netclient checkin -n all"|grep -v grep|awk '{print $1}')) local PID=$(ps|grep "netclient daemon"|grep -v grep|awk '{print $1}')
for i in "${PIDS[@]}"; do if [ "${PID}" ];then
kill $i kill ${PID}
done fi
echo "stop" echo "stop"
} }
status() { status() {
local PIDS=($(ps -e|grep "netclient checkin -n all"|grep -v grep|awk '{print $1}')) local PID=$(ps|grep "netclient daemon"|grep -v grep|awk '{print $1}')
if [ ${PIDS} ];then if [ "${PID}" ];then
echo -e "netclient[${PIDS}] is running \n" echo -e "netclient[${PID}] is running \n"
else else
echo -e "netclient is not running \n" echo -e "netclient is not running \n"
fi fi