forked from glideinWMS/glideinwms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_rpm_startup
executable file
·100 lines (83 loc) · 3.33 KB
/
create_rpm_startup
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/usr/bin/env python3
# SPDX-FileCopyrightText: 2009 Fermi Research Alliance, LLC
# SPDX-License-Identifier: Apache-2.0
import os
import stat
import sys
# STARTUP_DIR=sys.path[0]
# import os.path
# sys.path.append(os.path.join(STARTUP_DIR,"../.."))
# Create init.d compatible startup file
def create_initd_startup(
glideinWMS_dir_template, template_fname, startup_fname, work_dir, glideinWMS_dir, cfg_name, rpm_install=""
):
"""
Creates the frontend startup file and changes the permissions. Can overwrite an existing file.
"""
template = get_template(template_fname, glideinWMS_dir_template)
with open(startup_fname, "w") as fd:
if template_fname.startswith("frontend"):
template = template % {
"frontend_dir": work_dir,
"glideinWMS_dir": glideinWMS_dir,
"default_cfg_fpath": cfg_name,
"rpm_install": rpm_install,
}
else:
template = template % {
"factory_dir": work_dir,
"glideinWMS_dir": glideinWMS_dir,
"default_cfg_fpath": cfg_name,
"rpm_install": rpm_install,
}
fd.write(template)
os.chmod(startup_fname, stat.S_IRWXU | stat.S_IROTH | stat.S_IRGRP | stat.S_IXOTH | stat.S_IXGRP)
return
# Read startup file template
def get_template(template_name, glideinWMS_dir):
with open(f"{glideinWMS_dir}/creation/templates/{template_name}") as template_fd:
template_str = template_fd.read()
return template_str
def main(gwms_src_root_dir, template_frontend, template_factory, sfile_frontend, sfile_factory):
# Recreate the init.d startup files
# Commenting this out
# This is removing the files from gwms_src_root_dir + file_name
# The function create_initd_startup is creating the file as file_name
# and the open in write mode will delete an old file anyway
## Remove startup file if already exists
# for startup_fname in [sfile_frontend, sfile_factory]:
# if os.path.exists(os.path.join(gwms_src_root_dir, startup_fname)):
# os.remove(os.path.join(gwms_src_root_dir, startup_fname))
# Frontend
create_initd_startup(
gwms_src_root_dir,
template_frontend,
sfile_frontend,
"/var/lib/gwms-frontend/vofrontend",
"/var/lib/gwms-frontend/vofrontend",
"/etc/gwms-frontend/frontend.xml",
"True",
)
print("...Updated the frontend startup script")
# Factory
create_initd_startup(
gwms_src_root_dir,
template_factory,
sfile_factory,
"/var/lib/gwms-factory/work-dir",
"/var/lib/gwms-factory/work-dir",
"/etc/gwms-factory/glideinWMS.xml",
"True",
)
print("...Updated the factory startup script")
if __name__ == "__main__":
usage = """create_rpm_startup GWMS_DIR FRONTEND_STARTUP_TEMPLATE FACTORY_STARTUP_TEMPLATE FRONTEND_STARTUP FACTORY_STARTUP
Create or replace the FRONTEND_STARTUP FACTORY_STARTUP files in GWMS_DIR using the templates.
Both startup and template file names are relative to GWMS_DIR"""
argv = sys.argv[1:]
if len(argv) == 5 and not argv[0] in ["-h", "--help", "-help"]:
if os.path.isdir(argv[0]):
main(argv[0], argv[1], argv[2], argv[3], argv[4])
sys.exit(0)
print(usage)
sys.exit(1)