forked from SagerNet/sing-box
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sing-box-systemd
39 lines (38 loc) · 890 Bytes
/
sing-box-systemd
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
#!/bin/bash
### BEGIN INIT INFO
# Provides: sing-box
# Required-Start: $all
# Required-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: 启动时启动 sing-box
# Description: 启用 sing-box 提供的服务。
### END INIT INFO
case "$1" in
start)
systemctl start sing-box
;;
stop)
systemctl stop sing-box
;;
restart)
systemctl restart sing-box
;;
status)
echo "$(date) $(curl -x socks5://127.0.0.1:1080 -s https://speed.cloudflare.com/meta -m 5 | awk -F\" '{print $22}')"
;;
*)
for i in {1..10}; do
meta=$(curl -x socks5://127.0.0.1:1080 -s https://speed.cloudflare.com/meta -m 5 | awk -F\" '{print $22}')
echo "$(date) $meta"
if [[ "$meta" != "$1" ]]
then
systemctl restart sing-box
sleep 2
else
break
fi
done
;;
esac
exit 0