forked from juewuy/ShellCrash
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclashservice
46 lines (42 loc) · 1.06 KB
/
clashservice
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/bin/sh /etc/rc.common
START=99
SERVICE_DAEMONIZE=1
SERVICE_WRITE_PID=1
USE_PROCD=1
#获取目录
DIR=$(cat /etc/profile | grep clashdir | awk -F "\"" '{print $2}')
[ -z "$DIR" ] && DIR=$(cat ~/.bashrc | grep clashdir | awk -F "\"" '{print $2}')
BINDIR=$(cat $DIR/configs/ShellClash.cfg | grep bindir | awk -F "=" '{print $2}')
[ -z "$BINDIR" ] && BINDIR=$DIR
TMPDIR=/tmp/clash_$USER
start_service() {
#检测必须文件
$DIR/start.sh bfstart
if [ "$?" = "0" ];then
#使用procd创建clash后台进程
procd_open_instance
procd_set_param respawn
procd_set_param stderr 0
procd_set_param stdout 0
procd_set_param command $BINDIR/clash -d $BINDIR -f $TMPDIR/config.yaml
procd_close_instance
#其他设置
$DIR/start.sh afstart
fi
}
start() {
if [ -z "$(pidof procd)" ];then
#检测必须文件
$DIR/start.sh bfstart
if [ "$?" = "0" ];then
#创建后台进程
service_start $BINDIR/clash -d $BINDIR -f $TMPDIR/config.yaml
#其他设置
$DIR/start.sh afstart
#设置守护进程
$DIR/start.sh daemon
fi
else
start_service
fi
}