45 lines
1.1 KiB
Python
45 lines
1.1 KiB
Python
|
#. -*- coding: utf-8
|
||
|
#
|
||
|
# novnc daemon spawner
|
||
|
|
||
|
#import site packages
|
||
|
import shlex, subprocess
|
||
|
|
||
|
|
||
|
def spawn(target, options):
|
||
|
""" spawn """
|
||
|
vnctarget = '{}:{} {}:{} '.format(target['listen_host'], target['listen_port'], target['target_host'], target['target_port'])
|
||
|
|
||
|
a_options = ''
|
||
|
for key, value in options.items():
|
||
|
if value == True:
|
||
|
c_option = '--{} '.format(key)
|
||
|
else:
|
||
|
c_option = '--{} {} '.format(key, value)
|
||
|
a_options += c_option
|
||
|
|
||
|
command_line = 'python3 runwebsockify.py ' + a_options + vnctarget
|
||
|
args = shlex.split(command_line)
|
||
|
p = subprocess.Popen(args)
|
||
|
print('spawn!')
|
||
|
|
||
|
|
||
|
def spawn2(options):
|
||
|
""" spawn novnc daemon """
|
||
|
print('daemon spawned')
|
||
|
novncd = threading.Thread(name='novncd', target=start_websockify, args=(options,))
|
||
|
novncd.setDaemon(True) #daemonic ]:>
|
||
|
novncd.start()
|
||
|
print('stauts', novncd.isAlive())
|
||
|
|
||
|
|
||
|
def start_websockify(options):
|
||
|
""" spawn websockify process """
|
||
|
print(options)
|
||
|
server = websockify.WebSocketProxy(**options)
|
||
|
server.start_server()
|
||
|
print('daemon exited')
|
||
|
#while True:
|
||
|
# print('daemon')
|
||
|
|