-
Notifications
You must be signed in to change notification settings - Fork 0
/
start-daemon.sh
executable file
·229 lines (203 loc) · 8.32 KB
/
start-daemon.sh
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
#!/bin/sh
#
# Licensed under the Apache License, Version 2.0 (the "License");
# You may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0OA
#
# Authors:
# - Wen Guan, <wen.guan@cern.ch>, 2022 - 2023
IDDS_SERVICE=$1
source /etc/profile.d/conda.sh
conda activate /opt/idds;
export IDDS_HOME=/opt/idds
export ALEMBIC_CONFIG=/opt/idds/config/idds/alembic.ini
if [ -f /etc/grid-security/hostkey.pem ]; then
echo "host certificate is already created."
chmod 600 /etc/grid-security/hostkey.pem
elif [ -f /opt/idds/certs/hostkey.pem ]; then
echo "mount /opt/idds/certs/hostkey.pem to /etc/grid-security/hostkey.pem"
ln -fs /opt/idds/certs/hostkey.pem /etc/grid-security/hostkey.pem
ln -fs /opt/idds/certs/hostcert.pem /etc/grid-security/hostcert.pem
chmod 600 /etc/grid-security/hostkey.pem
fi
# setup intermediate certificate
if [ ! -f /etc/grid-security/chain.pem ]; then
if [ -f /opt/idds/certs/chain.pem ]; then
ln -fs /opt/idds/certs/chain.pem /etc/grid-security/chain.pem
elif [ -f /etc/grid-security/hostcert.pem ]; then
ln -fs /etc/grid-security/hostcert.pem /etc/grid-security/chain.pem
fi
fi
if [ -f /opt/idds/config/idds/idds.cfg ]; then
echo "idds.cfg already mounted."
else
echo "idds.cfg not found. will generate one."
python3 /opt/idds/tools/env/merge_idds_configs.py \
-s /opt/idds/config_default/idds.cfg $IDDS_OVERRIDE_IDDS_CONFIGS \
--use-env \
--prefix IDDS_CFG_IDDS \
-d /opt/idds/config/idds/idds.cfg
python3 /opt/idds/tools/env/merge_configmap.py \
-s /opt/idds/configmap/idds_configmap.json \
-d /opt/idds/config/idds/idds.cfg
fi
if [ -f /opt/idds/config/idds/alembic.ini ]; then
echo "alembic.ini already mounted."
else
echo "alembic.ini not found. will generate one."
cp /opt/idds/config_default/alembic.ini /opt/idds/config/idds/alembic.ini
python3 /opt/idds/tools/env/merge_configmap.py \
-s /opt/idds/configmap/idds_configmap.json \
-d /opt/idds/config/idds/alembic.ini
fi
if [ -f /opt/idds/config/idds/auth.cfg ]; then
echo "auth.cfg already mounted."
else
echo "auth.cfg not found. will generate one."
python3 /opt/idds/tools/env/merge_idds_configs.py \
-s /opt/idds/config_default/auth.cfg $IDDS_OVERRIDE_AUTH_CONFIGS \
--use-env \
--prefix IDDS_CFG_AUTH \
-d /opt/idds/config/idds/auth.cfg
if [ -f /opt/idds/configmap/auth.cfg.json ]; then
python3 /opt/idds/tools/env/merge_configmap.py \
-s /opt/idds/configmap/auth.cfg.json \
-d /opt/idds/config/idds/auth.cfg
fi
python3 /opt/idds/tools/env/merge_configmap.py \
-s /opt/idds/configmap/idds_configmap.json \
-d /opt/idds/config/idds/auth.cfg
fi
if [ -f /opt/idds/config/idds/gacl ]; then
echo "gacl already mounted."
else
echo "gacl not found. will generate one."
ln -s /opt/idds/config_default/gacl /opt/idds/config/idds/gacl
fi
if [ -f /opt/idds/config/panda.cfg ]; then
echo "panda.cfg already mounted."
else
echo "panda.cfg not found. will generate one."
python3 /opt/idds/tools/env/merge_idds_configs.py \
-s /opt/idds/config_default/panda.cfg $IDDS_OVERRIDE_PANDA_CONFIGS \
--use-env \
--prefix IDDS_CFG_PANDA \
-d /opt/idds/config/panda.cfg
python3 /opt/idds/tools/env/merge_configmap.py \
-s /opt/idds/configmap/idds_configmap.json \
-d /opt/idds/config/panda.cfg
fi
if [ -f /opt/idds/config/rucio.cfg ]; then
echo "rucio.cfg already mounted."
else
echo "rucio.cfg not found. will generate one."
python3 /opt/idds/tools/env/merge_idds_configs.py \
-s /opt/idds/config_default/rucio.cfg $IDDS_OVERRIDE_RUCIO_CONFIGS \
--use-env \
--prefix IDDS_CFG_RUCIO \
-d /opt/idds/config/rucio.cfg
python3 /opt/idds/tools/env/merge_configmap.py \
-s /opt/idds/configmap/idds_configmap.json \
-d /opt/idds/config/rucio.cfg
fi
# generate oidc token from environment
echo "generate oidc token from environment PANDA_AUTH_ID_TOKEN if it exists."
python3 /opt/idds/tools/env/merge_configmap.py --create_oidc_token
if [ -f /opt/idds/config/idds/httpd-idds-443-py39-cc7.conf ]; then
echo "httpd conf already mounted."
else
echo "httpd conf not found. will use the default one."
cp /opt/idds/config_default/httpd-idds-443-py39-cc7.conf /opt/idds/config/idds/httpd-idds-443-py39-cc7.conf
fi
if [ -f /opt/idds/config/idds/supervisord_idds.ini ]; then
echo "supervisord conf already mounted."
else
echo "supervisord conf not found. will use the default one."
cp /opt/idds/config_default/supervisord_idds.ini /opt/idds/config/idds/supervisord_idds.ini
cp /opt/idds/config_default/supervisord_iddsfake.ini /opt/idds/config/idds/supervisord_iddsfake.ini
cp /opt/idds/config_default/supervisord_httpd.ini /opt/idds/config/idds/supervisord_httpd.ini
cp /opt/idds/config_default/supervisord_syslog-ng.ini /opt/idds/config/idds/supervisord_syslog-ng.ini
fi
if [ -f /etc/grid-security/hostkey.pem ]; then
echo "Host certificate already mounted."
else
echo "Host certificate not found. will generate a self-signed one."
openssl req -x509 -nodes -days 365 -newkey rsa:2048 \
-subj "/C=US/DC=IDDS/OU=computers/CN=$(hostname -f)" \
-keyout /opt/idds/config/hostkey.pem \
-out /opt/idds/config/hostcert.pem
ln -fs /opt/idds/config/hostcert.pem /etc/grid-security/hostcert.pem
ln -fs /opt/idds/config/hostkey.pem /etc/grid-security/hostkey.pem
chmod 600 /etc/grid-security/hostkey.pem
fi
mkdir -p /opt/idds/config/.panda/
if [ ! -z "$IDDS_PRINT_CFG" ]; then
echo "=================== /opt/idds/etc/idds.cfg ============================"
cat /opt/idds/etc/idds.cfg
echo ""
echo "=================== /opt/idds/etc/idds/auth/auth.cfg ============================"
cat /opt/idds/etc/idds/auth/auth.cfg
echo ""
echo "=================== /opt/idds/etc/idds/rest/gacl ============================"
cat /opt/idds/etc/idds/rest/gacl
echo ""
echo "=================== /etc/httpd/conf.d/httpd-idds-443-py39-cc7.conf ============================"
cat /etc/httpd/conf.d/httpd-idds-443-py39-cc7.conf
echo ""
echo "=================== /opt/idds/config/idds/supervisord_idds.ini ============================"
cat /opt/idds/config/idds/supervisord_idds.ini
echo ""
echo "=================== /opt/idds/etc/panda/panda.cfg ============================"
cat /opt/idds/etc/panda/panda.cfg
echo ""
echo "=================== /opt/idds/etc/rucio.cfg ============================"
cat /opt/idds/etc/rucio.cfg
echo ""
fi
# create database if not exists
python /opt/idds/tools/env/create_database.py
# upgrade database
alembic upgrade head
# configure monitor
python /opt/idds/tools/env/config_monitor.py -s ${IDDS_HOME}/monitor/data/conf.js.template -d ${IDDS_HOME}/monitor/data/conf.js --host ${IDDS_SERVER}
if ! [ -f /opt/idds/config/.token ]; then
echo "/opt/idds/config/.token does not exist."
if [ -f /opt/idds/configmap/idds2panda_token ]; then
ln -s /opt/idds/configmap/idds2panda_token /opt/idds/config/.token
fi
fi
# start redis
mkdir /var/log/idds/redis
if [ ! -f /var/log/redis ]; then
ln -s /var/log/idds/redis /var/log/redis
fi
if [ ! -f /var/lib/redis ]; then
ln -s /var/log/idds/redis /var/lib/redis
fi
/usr/bin/redis-server /etc/redis.conf --supervised systemd &
if [ "${IDDS_SERVICE}" == "rest" ]; then
echo "starting iDDS ${IDDS_SERVICE} service"
# systemctl restart httpd.service
# systemctl enable httpd.service
# systemctl status httpd.service
/usr/sbin/httpd
elif [ "${IDDS_SERVICE}" == "daemon" ]; then
echo "starting iDDS ${IDDS_SERVICE} service"
# systemctl enable supervisord
# systemctl start supervisord
# systemctl status supervisord
/usr/bin/supervisord -c /etc/supervisord.conf
elif [ "${IDDS_SERVICE}" == "all" ]; then
echo "starting iDDS rest service"
# /usr/sbin/httpd
echo "starting iDDS daemon service"
/usr/bin/supervisord -c /etc/supervisord.conf
else
exec "$@"
fi
# echo "start syslog-ng"
# /usr/sbin/syslog-ng -F --no-caps --persist-file=/var/log/idds/syslog-ng.persist -p /var/log/idds/syslog-ng.pid
tail -f -F /var/log/idds/syslog-ng-stdout.log &
tail -f -F /var/log/idds/syslog-ng-stderr.log &
trap : TERM INT; sleep infinity & wait