#!/bin/sh /etc/rc.common
START=50

run_syncthing()
{
	local enabled
	config_get_bool enabled $1 enabled
	if [ $enabled = 1 ]; then
	local port
	config_get port $1 port
	state=`pgrep syncthing | wc -l`
	if [ $state = 0 ] ; then
		export HOME="/root"
        syncthing -gui-address="0.0.0.0:$port" -logfile="/var/log/syncthing.log" -no-browser >/dev/null &
	echo "启动中..."
	start=`pgrep syncthing | wc -l`
	if [ $start = 0 ] ; then
	echo "启动失败"
	else
	echo "启动成功"
	fi
	else
	echo "已在运行"
	fi
	fi
}

start()
{
	config_load "luci-app-syncthing"
	config_foreach run_syncthing setting
}

stop()
{
	kill -9 `pgrep syncthing`
	stop=`pgrep syncthing | wc -l`
	if [ $stop = 0 ] ; then
	echo "已停止运行"
	else
	echo "未停止运行"
	fi
}
