Simple Linux Panel
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
mdserver-web/plugins/bbr/index.py

110 lines
2.3 KiB

6 years ago
# coding: utf-8
import time
import random
import os
import json
import re
import sys
sys.path.append(os.getcwd() + "/class/core")
import mw
6 years ago
6 years ago
app_debug = False
if mw.isAppleSystem():
6 years ago
app_debug = True
6 years ago
def getPluginName():
return 'bbr'
def getPluginDir():
return mw.getPluginDir() + '/' + getPluginName()
6 years ago
def getServerDir():
return mw.getServerDir() + '/' + getPluginName()
6 years ago
def getInitDFile():
if app_debug:
return '/tmp/' + getPluginName()
return '/etc/init.d/' + getPluginName()
6 years ago
6 years ago
def getArgs():
args = sys.argv[2:]
tmp = {}
args_len = len(args)
if args_len == 1:
t = args[0].strip('{').strip('}')
t = t.split(':')
tmp[t[0]] = t[1]
elif args_len > 1:
for i in range(len(args)):
t = args[i].split(':')
tmp[t[0]] = t[1]
return tmp
6 years ago
6 years ago
def status():
6 years ago
if not app_debug:
if mw.isAppleSystem():
6 years ago
return "stop"
6 years ago
data = mw.execShell('sudo sysctl -n net.ipv4.tcp_congestion_control')
6 years ago
r = data[0].strip()
if r == 'bbr':
return 'start'
return 'stop'
6 years ago
6 years ago
def start():
if not app_debug:
if mw.isAppleSystem():
6 years ago
return "Apple Computer does not support"
mw.execShell('echo "net.core.default_qdisc=fq" >> /etc/sysctl.conf')
6 years ago
cmd = 'echo "net.ipv4.tcp_congestion_control=bbr" >> /etc/sysctl.conf'
mw.execShell(cmd)
mw.execShell('sysctl -p')
6 years ago
return '执行成功!重启系统生效'
6 years ago
def stop():
if not app_debug:
if mw.isAppleSystem():
6 years ago
return "Apple Computer does not support"
6 years ago
cmd1 = "sed -i '/net\.core\.default_qdisc/d' /etc/sysctl.conf"
mw.execShell(cmd1)
6 years ago
cmd2 = "sed -i '/net\.ipv4\.tcp_congestion_control/d' /etc/sysctl.conf"
mw.execShell(cmd2)
mw.execShell("sysctl -p")
6 years ago
return '执行成功!重启系统生效'
6 years ago
def restart():
return '无效'
def reload():
return '无效'
6 years ago
if __name__ == "__main__":
func = sys.argv[1]
if func == 'status':
print status()
6 years ago
elif func == 'start':
print start()
elif func == 'stop':
print stop()
elif func == 'restart':
print restart()
elif func == 'reload':
print reload()