update install.sh
authorPeng Li <seudut@gmail.com>
Fri, 22 Jun 2018 07:41:15 +0000 (15:41 +0800)
committerPeng Li <seudut@gmail.com>
Fri, 22 Jun 2018 07:41:15 +0000 (15:41 +0800)
install.sh
suanzi-support

index acbf196..9c4f7ff 100755 (executable)
@@ -2,6 +2,9 @@
 
 SERVICE='suanzi-support.service'
 
+echo 'Install dependencies'
+apt install sshpass || exit 1
+pip install paho-mqtt || exit 1
 
 echo 'Install suanzi-support'
 cp suanzi-support /usr/local/bin/ || exit 1
index 41ed9fc..8809b05 100755 (executable)
@@ -13,17 +13,20 @@ from uuid import getnode as get_mac
 
 MQTT_SERVER = 'mqtt.suanzi.ai'
 MQTT_PORT = 1883
+
+# The alive time new ssh session exist. It means if no client connect to this device through ssh tunnel in 5 minutes,
+# this new sessin will terminate.
 ALIVE_TIME = 60 * 5
 
 SSH_SERVER = 'autossh.suanzi.ai'
-PORT_RANGE = (20000, 30000)
+PORT_RANGE = (20000, 40000)
 USER = 'autossh'
 PASSWORD = 'hard2guess'
 
 def getAvailablePort(host, ports):
     while True:
         port = random.randint(ports[0], ports[1])
-        command = 'nc -z -v -w5 ' + host + ' ' + str(port)
+        command = 'nc -z -v -w3 ' + host + ' ' + str(port)
         p = Popen(command, shell=True, stdout=PIPE, stderr=STDOUT)
         pout = p.communicate()[0].strip()
         if p.returncode == 0:
@@ -36,14 +39,12 @@ def getAvailablePort(host, ports):
 def exec_ssh(port):
     if port == None:
         raise Exception('Port not avaliable')
-    #command = 'sshpass -p' + PASSWORD + ' ssh -o "ServerAliveInterval 30" -o "ServerAliveCountMax 1" -fCNR ' + str(port) +':localhost:22 ' + USER + '@' + SSH_SERVER
     command = 'sshpass -p' + PASSWORD + ' ssh -o "ServerAliveInterval 60" -o "ServerAliveCountMax 3" -fCR ' + str(port) +':localhost:22 ' + USER + '@' + SSH_SERVER + ' sleep ' + str(ALIVE_TIME)
     print command
     return call(shlex.split(command), shell=False)
 
 
 def on_connect(client, userdata, flags, rc):
-    #client.subscribe("rpdzkj-request")
     client.subscribe(client.id + '-request')
     print("Connected with result code "+str(rc))