Browse Source

insert a reload step

main thread run 'thread_db' directly
insert a 'ulimit' command before run the server
dev
breakwa11 9 years ago
parent
commit
c73127d858
  1. 3
      db_transfer.py
  2. 5
      run.sh
  3. 13
      server.py
  4. 2
      stop.sh
  5. 2
      tail.sh

3
db_transfer.py

@ -78,9 +78,11 @@ class DbTransfer(object):
#数据库所有用户信息 #数据库所有用户信息
try: try:
import switchrule import switchrule
reload(switchrule)
keys = switchrule.getKeys() keys = switchrule.getKeys()
except Exception as e: except Exception as e:
keys = ['port', 'u', 'd', 'transfer_enable', 'passwd', 'enable' ] keys = ['port', 'u', 'd', 'transfer_enable', 'passwd', 'enable' ]
reload(cymysql)
conn = cymysql.connect(host=Config.MYSQL_HOST, port=Config.MYSQL_PORT, user=Config.MYSQL_USER, conn = cymysql.connect(host=Config.MYSQL_HOST, port=Config.MYSQL_PORT, user=Config.MYSQL_USER,
passwd=Config.MYSQL_PASS, db=Config.MYSQL_DB, charset='utf8') passwd=Config.MYSQL_PASS, db=Config.MYSQL_DB, charset='utf8')
cur = conn.cursor() cur = conn.cursor()
@ -102,6 +104,7 @@ class DbTransfer(object):
#需要动态载入switchrule,以便实时修改规则 #需要动态载入switchrule,以便实时修改规则
try: try:
import switchrule import switchrule
reload(switchrule)
except Exception as e: except Exception as e:
logging.error('load switchrule.py fail') logging.error('load switchrule.py fail')
cur_servers = {} cur_servers = {}

5
run.sh

@ -1,5 +1,6 @@
#!/bin/bash #!/bin/bash
cd `dirname $0` cd `dirname $0`
eval $(ps -ef | grep "[0-9] python server\\.py" | awk '{print "kill "$2}') eval $(ps -ef | grep "[0-9] python server\\.py m" | awk '{print "kill "$2}')
nohup python server.py >> ssserver.log 2>&1 & ulimit -n 131072
nohup python server.py m>> ssserver.log 2>&1 &

13
server.py

@ -7,6 +7,7 @@ os.chdir(os.path.split(os.path.realpath(__file__))[0])
import server_pool import server_pool
import db_transfer import db_transfer
from shadowsocks import shell
#def test(): #def test():
# thread.start_new_thread(DbTransfer.thread_db, ()) # thread.start_new_thread(DbTransfer.thread_db, ())
@ -19,10 +20,16 @@ class MainThread(threading.Thread):
def run(self): def run(self):
db_transfer.DbTransfer.thread_db() db_transfer.DbTransfer.thread_db()
if __name__ == '__main__': def main():
#server_pool.ServerPool.get_instance() shell.check_python()
#server_pool.ServerPool.get_instance().new_server(2333, '2333') if len(sys.argv) <= 3:
db_transfer.DbTransfer.thread_db()
else:
thread = MainThread() thread = MainThread()
thread.start() thread.start()
while True: while True:
time.sleep(99999) time.sleep(99999)
if __name__ == '__main__':
main()

2
stop.sh

@ -1,3 +1,3 @@
#!/bin/bash #!/bin/bash
eval $(ps -ef | grep "[0-9] python server\\.py" | awk '{print "kill "$2}') eval $(ps -ef | grep "[0-9] python server\\.py m" | awk '{print "kill "$2}')

2
tail.sh

@ -1,3 +1,3 @@
#!/bin/bash #!/bin/bash
cd `dirname $0`
tail -f ssserver.log tail -f ssserver.log

Loading…
Cancel
Save