mirror of
https://github.com/Py-KMS-Organization/py-kms.git
synced 2025-05-13 06:34:45 -04:00
lint dockerfile, set TZ and UID/GID, have client log.
This commit is contained in:
parent
e620e9236a
commit
f9e7df6af9
4 changed files with 175 additions and 49 deletions
|
@ -1,9 +1,10 @@
|
|||
#!/usr/bin/python3
|
||||
|
||||
# This replaces the old start.sh and ensures all arguments are bound correctly from the environment variables...
|
||||
# Need root privileges to change timezone, and user uid/gid
|
||||
|
||||
import grp
|
||||
import os
|
||||
import time
|
||||
import pwd
|
||||
import subprocess
|
||||
|
||||
argumentVariableMapping = {
|
||||
|
@ -19,6 +20,21 @@ argumentVariableMapping = {
|
|||
}
|
||||
sqliteWebPath = '/home/sqlite_web/sqlite_web.py'
|
||||
|
||||
def change_uid_grp():
|
||||
user_db_entries = pwd.getpwnam("py-kms")
|
||||
user_grp_db_entries = grp.getgrnam("power_users")
|
||||
uid = user_db_entries.pw_uid
|
||||
gid = user_grp_db_entries.gr_gid
|
||||
new_gid = int(os.getenv('GID', str(gid)))
|
||||
new_uid = int(os.getenv('UID', str(uid)))
|
||||
os.chown("/home/py-kms", new_uid, new_uid)
|
||||
os.chown("/db/pykms_database.db", new_uid, new_uid)
|
||||
if gid != new_gid:
|
||||
print("Setting gid to " + str(new_gid), flush=True)
|
||||
os.setgid(gid)
|
||||
if uid != new_uid:
|
||||
print("Setting uid to " + str(new_uid), flush=True)
|
||||
os.setuid(uid)
|
||||
# Build the command to execute
|
||||
listenIP = os.environ.get('IP', '0.0.0.0')
|
||||
listenPort = os.environ.get('PORT', '1688')
|
||||
|
@ -36,8 +52,14 @@ if enableSQLITE:
|
|||
command.append('-s')
|
||||
command.append(dbPath)
|
||||
|
||||
pykmsProcess = subprocess.Popen(command)
|
||||
|
||||
def change_tz():
|
||||
tz = os.getenv('TZ', 'etc/UTC')
|
||||
# TZ is not symlinked and defined TZ exists
|
||||
if tz not in os.readlink(LTIME) and os.path.isfile('/usr/share/zoneinfo/' + tz):
|
||||
print("Setting timezone to " + tz, flush=True)
|
||||
os.remove(LTIME)
|
||||
os.symlink(os.path.join('/usr/share/zoneinfo/', tz), LTIME)
|
||||
# In case SQLITE is defined: Start the web interface
|
||||
if enableSQLITE:
|
||||
time.sleep(5) # The server may take a while to start
|
||||
|
@ -46,12 +68,13 @@ if enableSQLITE:
|
|||
subprocess.run(['/usr/bin/python3', 'pykms_Client.py', listenIP, listenPort, '-m', 'Windows10', '-n', 'DummyClient', '-c', 'ae3a27d1-b73a-4734-9878-70c949815218'])
|
||||
sqliteProcess = subprocess.Popen(['/usr/bin/python3', sqliteWebPath, '-H', listenIP, '--read-only', '-x', dbPath, '-p', os.environ.get('SQLITE_PORT', 8080)])
|
||||
|
||||
try:
|
||||
pykmsProcess.wait()
|
||||
except:
|
||||
# In case of any error - just shut down
|
||||
pass
|
||||
|
||||
if enableSQLITE:
|
||||
sqliteProcess.terminate()
|
||||
pykmsProcess.terminate()
|
||||
LTIME = '/etc/localtime'
|
||||
PYTHON3 = '/usr/bin/python3'
|
||||
log_level = os.getenv('LOGLEVEL', 'INFO')
|
||||
|
||||
# Main
|
||||
if (__name__ == "__main__"):
|
||||
change_tz()
|
||||
change_uid_grp()
|
||||
subprocess.call("/usr/bin/start.py",shell=True)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue