-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathclash
61 lines (47 loc) · 1.19 KB
/
clash
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/bin/sh
# PROVIDE: clash
# REQUIRE: NETWORKING
# KEYWORD: shutdown
. /etc/rc.subr
name="clash"
rcvar=clash_enable
log_file="/var/log/clash.log"
command=/usr/sbin/daemon
command_args="-P /var/run/clash.pid /usr/local/bin/clash -d /usr/local/etc/clash/ >>$log_file"
pidfile=/var/run/${name}.pid
status_cmd=clash_status
: ${clash_enable="NO"}
log_message() {
echo "$(date '+%Y-%m-%d %H:%M:%S') - $1" >> $log_file
}
clash_status()
{
if [ -n "$rc_pid" ]; then
log_message "${name} is running as pid $rc_pid."
echo "${name} is running as pid $rc_pid."
return 0
else
log_message "${name} is not running."
echo "${name} is not running."
fi
}
start_clash()
{
log_message "Starting ${name}..."
$command $command_args >> $log_file 2>&1 &
echo $! > /var/run/clash.pid
log_message "${name} started with pid $(cat /var/run/clash.pid)."
}
stop_clash()
{
log_message "Stopping ${name}..."
if [ -f /var/run/clash.pid ]; then
kill $(cat /var/run/clash.pid)
rm -f /var/run/clash.pid
log_message "${name} stopped."
else
log_message "No ${name} pid file found."
fi
}
load_rc_config clash
run_rc_command $1