This repository has been archived by the owner on Apr 27, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 926
/
startup.py
executable file
·78 lines (62 loc) · 1.78 KB
/
startup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/usr/bin/python
#
# MDN Sample Server
# Start up samples as needed.
#
# Any copyright is dedicated to the Public Domain.
# http://creativecommons.org/publicdomain/zero/1.0/
#
import os
import sys
import subprocess
import pwd
#
# startService
#
# Given a path, start up the service contained in that directory.
# This is done by running the "startup.sh" script in each directory.
# The bash shell is used.
#
def startService(path):
print("Starting service: " + path)
startupScript = path + "/" + "startup.sh"
if os.path.exists(startupScript):
sys.stdout.flush()
# pw_record = pwd.getpwnam("apache")
# env = os.environ.copy()
# env['HOME'] = pw_record.pw_dir
# env['LOGNAME'] = pw_record.pw_name
# env['PWD'] = path
# env['USER'] = pw_record.pw_name
process = subprocess.Popen(
# ["/bin/bash", startupScript], cwd = path, env = env, preexec_fn=demoteUser(pw_record.pw_uid, pw_record.pw_gid)
["/bin/bash", startupScript], cwd = path
)
# TODO: At some point we should record process IDs for restarts/shutdowns/etc
#
# demoteUser
#
# Downgrade to execute the process using the specified user ID and group ID.
#
def demoteUser(user_uid, user_gid):
def result():
os.setgid(user_gid)
os.setuid(user_uid)
return result
#
# Main program
#
# Get the Web content directory, tack on "/s", and get a list of the
# contents of that directory
scriptDir = os.path.dirname(os.path.abspath(__file__))
if not scriptDir.endswith("/"):
scriptDir += "/"
serviceDir = scriptDir + "s"
serviceList = os.listdir(serviceDir)
# For each directory in the service directory,
# call startService() to start it up.
for name in serviceList:
if name[0] != '.':
path = serviceDir + "/" + name
if os.path.isdir(path):
startService(path)