netmaker/scripts/openwrt-daemon.sh

45 lines
1 KiB
Bash
Raw Normal View History

#!/bin/sh /etc/rc.common
2021-11-07 23:54:34 +08:00
#Created by oycol<oycol527@outlook.com>
2021-11-06 05:03:09 +08:00
EXTRA_COMMANDS="status"
EXTRA_HELP=" status Check service is running"
2021-11-06 05:03:09 +08:00
START=99
LOG_FILE="/tmp/netclient.logs"
start() {
mkdir -p /etc/netclient/config
mkdir -p /etc/systemd/system
2021-11-07 23:54:34 +08:00
if [ ! -f "${LOG_FILE}" ];then
touch "${LOG_FILE}"
fi
local PID=$(ps|grep "netclient daemon"|grep -v grep|awk '{print $1}')
if [ "${PID}" ];then
2021-11-06 05:03:09 +08:00
echo "service is running"
return
fi
/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 &"
2021-11-06 05:03:09 +08:00
echo "start"
}
stop() {
local PID=$(ps|grep "netclient daemon"|grep -v grep|awk '{print $1}')
if [ "${PID}" ];then
kill ${PID}
fi
2021-11-06 05:03:09 +08:00
echo "stop"
}
status() {
local PID=$(ps|grep "netclient daemon"|grep -v grep|awk '{print $1}')
if [ "${PID}" ];then
echo -e "netclient[${PID}] is running \n"
2021-11-06 05:03:09 +08:00
else
echo -e "netclient is not running \n"
fi
}