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. 19
      server.py
  4. 2
      stop.sh
  5. 2
      tail.sh

3
db_transfer.py

@ -78,9 +78,11 @@ class DbTransfer(object):
#数据库所有用户信息
try:
import switchrule
reload(switchrule)
keys = switchrule.getKeys()
except Exception as e:
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,
passwd=Config.MYSQL_PASS, db=Config.MYSQL_DB, charset='utf8')
cur = conn.cursor()
@ -102,6 +104,7 @@ class DbTransfer(object):
#需要动态载入switchrule,以便实时修改规则
try:
import switchrule
reload(switchrule)
except Exception as e:
logging.error('load switchrule.py fail')
cur_servers = {}

5
run.sh

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

19
server.py

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

2
stop.sh

@ -1,3 +1,3 @@
#!/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
cd `dirname $0`
tail -f ssserver.log

Loading…
Cancel
Save