mirror of
https://github.com/Py-KMS-Organization/py-kms.git
synced 2025-05-14 07:04:52 -04:00
use unbuffered output globally.
This commit is contained in:
parent
d2394cd1bd
commit
6d7124414a
2 changed files with 15 additions and 16 deletions
|
@ -1,6 +1,6 @@
|
||||||
#!/usr/bin/python3
|
#!/usr/bin/python3 -u
|
||||||
|
|
||||||
# Need root privileges to change timezone, and user uid/gid
|
# Need root privileges to change timezone, and user uid/gid, file/folder ownernship
|
||||||
|
|
||||||
import grp
|
import grp
|
||||||
import os
|
import os
|
||||||
|
@ -24,10 +24,10 @@ def change_uid_grp():
|
||||||
if os.path.isfile(dbPath): os.chown(dbPath, new_uid, new_gid)
|
if os.path.isfile(dbPath): os.chown(dbPath, new_uid, new_gid)
|
||||||
os.system("ls -al /usr/bin/start.py")
|
os.system("ls -al /usr/bin/start.py")
|
||||||
if gid != new_gid:
|
if gid != new_gid:
|
||||||
print("Setting gid to " + str(new_gid), flush=True)
|
print("Setting gid to " + str(new_gid))
|
||||||
os.setgid(gid)
|
os.setgid(gid)
|
||||||
if uid != new_uid:
|
if uid != new_uid:
|
||||||
print("Setting uid to " + str(new_uid), flush=True)
|
print("Setting uid to " + str(new_uid))
|
||||||
os.setuid(uid)
|
os.setuid(uid)
|
||||||
|
|
||||||
|
|
||||||
|
@ -35,7 +35,7 @@ def change_tz():
|
||||||
tz = os.getenv('TZ', 'etc/UTC')
|
tz = os.getenv('TZ', 'etc/UTC')
|
||||||
# TZ is not symlinked and defined TZ exists
|
# TZ is not symlinked and defined TZ exists
|
||||||
if tz not in os.readlink('/etc/localtime') and os.path.isfile('/usr/share/zoneinfo/' + tz):
|
if tz not in os.readlink('/etc/localtime') and os.path.isfile('/usr/share/zoneinfo/' + tz):
|
||||||
print("Setting timezone to " + tz, flush=True)
|
print("Setting timezone to " + tz)
|
||||||
os.remove('/etc/localtime')
|
os.remove('/etc/localtime')
|
||||||
os.symlink(os.path.join('/usr/share/zoneinfo/', tz), '/etc/localtime')
|
os.symlink(os.path.join('/usr/share/zoneinfo/', tz), '/etc/localtime')
|
||||||
|
|
||||||
|
@ -43,4 +43,4 @@ def change_tz():
|
||||||
# Main
|
# Main
|
||||||
if (__name__ == "__main__"):
|
if (__name__ == "__main__"):
|
||||||
change_tz()
|
change_tz()
|
||||||
subprocess.call(PYTHON3 + " /usr/bin/start.py", preexec_fn=change_uid_grp(), shell=True)
|
subprocess.call(PYTHON3 + " -u /usr/bin/start.py", preexec_fn=change_uid_grp(), shell=True)
|
||||||
|
|
|
@ -1,11 +1,10 @@
|
||||||
#!/usr/bin/python3
|
#!/usr/bin/python3 -u
|
||||||
|
|
||||||
# This replaces the old start.sh and ensures all arguments are bound correctly from the environment variables...
|
# This replaces the old start.sh and ensures all arguments are bound correctly from the environment variables...
|
||||||
import os
|
import os
|
||||||
import subprocess
|
import subprocess
|
||||||
import time
|
import time
|
||||||
|
|
||||||
LTIME = '/etc/localtime'
|
|
||||||
PYTHON3 = '/usr/bin/python3'
|
PYTHON3 = '/usr/bin/python3'
|
||||||
argumentVariableMapping = {
|
argumentVariableMapping = {
|
||||||
'-l': 'LCID',
|
'-l': 'LCID',
|
||||||
|
@ -28,7 +27,7 @@ log_level = os.getenv('LOGLEVEL', 'INFO')
|
||||||
def start_kms_client():
|
def start_kms_client():
|
||||||
if not os.path.isfile(dbPath):
|
if not os.path.isfile(dbPath):
|
||||||
# Start a dummy activation to ensure the database file is created
|
# Start a dummy activation to ensure the database file is created
|
||||||
client_cmd = [PYTHON3, 'pykms_Client.py', os.environ.get('IP', "0.0.0.0"), os.environ.get('PORT', 1688),
|
client_cmd = [PYTHON3,'-u', 'pykms_Client.py', os.environ.get('IP', "0.0.0.0"), os.environ.get('PORT', 1688),
|
||||||
'-m', 'Windows10', '-n', 'DummyClient', '-c', 'ae3a27d1-b73a-4734-9878-70c949815218',
|
'-m', 'Windows10', '-n', 'DummyClient', '-c', 'ae3a27d1-b73a-4734-9878-70c949815218',
|
||||||
'-V', os.environ.get('LOGLEVEL', 'INFO'), '-F', os.environ.get('LOGFILE', 'STDOUT')]
|
'-V', os.environ.get('LOGLEVEL', 'INFO'), '-F', os.environ.get('LOGFILE', 'STDOUT')]
|
||||||
if os.environ.get('LOGSIZE', '') != "":
|
if os.environ.get('LOGSIZE', '') != "":
|
||||||
|
@ -36,28 +35,28 @@ def start_kms_client():
|
||||||
client_cmd.append(os.environ.get('LOGSIZE'))
|
client_cmd.append(os.environ.get('LOGSIZE'))
|
||||||
|
|
||||||
if log_level.lower() in ['info', 'debug']:
|
if log_level.lower() in ['info', 'debug']:
|
||||||
print("Starting a dummy activation to ensure the database file is created", flush=True)
|
print("Starting a dummy activation to ensure the database file is created")
|
||||||
if log_level.lower() == 'debug':
|
if log_level.lower() == 'debug':
|
||||||
print("client_cmd: " + str(client_cmd), flush=True)
|
print("client_cmd: " + str(client_cmd))
|
||||||
|
|
||||||
subprocess.run(client_cmd)
|
subprocess.run(client_cmd)
|
||||||
|
|
||||||
|
|
||||||
def start_kms():
|
def start_kms():
|
||||||
# Build the command to execute
|
# Build the command to execute
|
||||||
command = [PYTHON3, 'pykms_Server.py', os.environ.get('IP'), os.environ.get('PORT')]
|
command = [PYTHON3,'-u', 'pykms_Server.py', os.environ.get('IP'), os.environ.get('PORT')]
|
||||||
for (arg, env) in argumentVariableMapping.items():
|
for (arg, env) in argumentVariableMapping.items():
|
||||||
if env in os.environ and os.environ.get(env) != '':
|
if env in os.environ and os.environ.get(env) != '':
|
||||||
command.append(arg)
|
command.append(arg)
|
||||||
command.append(os.environ.get(env))
|
command.append(os.environ.get(env))
|
||||||
|
|
||||||
if enableSQLITE:
|
if enableSQLITE:
|
||||||
print('Storing database file to ' + dbPath, flush=True)
|
print('Storing database file to ' + dbPath)
|
||||||
command.append('-s')
|
command.append('-s')
|
||||||
command.append(dbPath)
|
command.append(dbPath)
|
||||||
|
|
||||||
if log_level.lower() == 'debug':
|
if log_level.lower() == 'debug':
|
||||||
print("server_cmd: " + str(command), flush=True)
|
print("server_cmd: " + str(command))
|
||||||
|
|
||||||
pykms_process = subprocess.Popen(command)
|
pykms_process = subprocess.Popen(command)
|
||||||
|
|
||||||
|
@ -66,11 +65,11 @@ def start_kms():
|
||||||
time.sleep(5) # The server may take a while to start
|
time.sleep(5) # The server may take a while to start
|
||||||
os.system('ls -al ' + dbPath)
|
os.system('ls -al ' + dbPath)
|
||||||
start_kms_client()
|
start_kms_client()
|
||||||
sqlite_cmd = [PYTHON3, '/home/sqlite_web/sqlite_web.py', '-H', os.environ.get('IP'), '--read-only', '-x', dbPath,
|
sqlite_cmd = [PYTHON3,'-u', '/home/sqlite_web/sqlite_web.py', '-H', os.environ.get('IP'), '--read-only', '-x', dbPath,
|
||||||
'-p', os.environ.get('SQLITE_PORT')]
|
'-p', os.environ.get('SQLITE_PORT')]
|
||||||
|
|
||||||
if log_level.lower() == 'debug':
|
if log_level.lower() == 'debug':
|
||||||
print("sqlite_cmd: " + str(sqlite_cmd), flush=True)
|
print("sqlite_cmd: " + str(sqlite_cmd))
|
||||||
|
|
||||||
sqlite_process = subprocess.Popen(sqlite_cmd)
|
sqlite_process = subprocess.Popen(sqlite_cmd)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue