Skip to content

Commit 7cd60be

Browse files
committed
update server start
1 parent 5444a9d commit 7cd60be

File tree

2 files changed

+28
-6
lines changed

2 files changed

+28
-6
lines changed
Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,21 @@
1+
import argparse
12
import sys
23
import os
3-
os.chdir('..')
4-
path = os.path.dirname(__file__)
5-
path = str(path)+'server.py'
6-
os.system('sudo nohup python3 '+path+' &')
4+
if __name__ == '__main__':
5+
parser=argparse.ArgumentParser()
6+
parser.add_argument("-p", type=int)
7+
parser.add_argument("-ip", type=str)
8+
args=parser.parse_args()
9+
port_num = args.p
10+
ip_addr = args.ip
11+
if ip_addr != None and port_num != None:
12+
os.chdir('..')
13+
path = os.path.dirname(__file__)
14+
path = str(path)+'server.py'
15+
os.system('sudo nohup python3 '+path+' &')
16+
else:
17+
print('false')
18+
os.chdir('..')
19+
path = os.path.dirname(__file__)
20+
path = str(path)+'server.py'
21+
os.system('sudo nohup python3 '+path+' &')

TAKfreeServer/TAKWinService/beginProgramAsService.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import threading
99
import sys
1010
import os
11+
import argparse
1112
PACKAGE_PARENT = '..'
1213
SCRIPT_DIR = os.path.dirname(os.path.realpath(os.path.join(os.getcwd(), os.path.expanduser(__file__))))
1314
sys.path.append(os.path.normpath(os.path.join(SCRIPT_DIR, PACKAGE_PARENT)))
@@ -18,6 +19,7 @@ class AppServerSvc (win32serviceutil.ServiceFramework):
1819
killSwitch = 0
1920

2021
def __init__(self,args):
22+
print(args)
2123
win32serviceutil.ServiceFramework.__init__(self,args)
2224
self.hWaitStop = win32event.CreateEvent(None,0,0,None)
2325

@@ -31,7 +33,7 @@ def SvcDoRun(self):
3133
self.main()
3234

3335
def main(self):
34-
t = threading.Thread(target = ThreadedServer('',8087).listen, args = (), daemon=True)
36+
t = threading.Thread(target = ThreadedServer(ip,port).listen, args = (), daemon=True)
3537
t.start()
3638
while True:
3739
if self.killSwitch == 1:
@@ -40,4 +42,9 @@ def main(self):
4042
True
4143

4244
if __name__ == '__main__':
43-
win32serviceutil.HandleCommandLine(AppServerSvc)
45+
if sys.argv[1] == 'start':
46+
ip = input('please enter your server IP: ')
47+
port = int(input('please enter the port your server should be listening on: '))
48+
win32serviceutil.HandleCommandLine(AppServerSvc)
49+
else:
50+
win32serviceutil.HandleCommandLine(AppServerSvc)

0 commit comments

Comments
 (0)