forked from nashcom/domino-startscript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrc_domino
423 lines (351 loc) · 11.2 KB
/
rc_domino
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
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
#!/bin/bash
# change this to #!/bin/ksh for AIX
###########################################################################
# RC RunLevel Entry Point
###########################################################################
# Start/Stop Script for Domino on xLinux/zLinux/AIX
# 2005-2022 Copyright by Daniel Nashed, feedback domino_unix@nashcom.de
# You may use and distribute the unmodified version of this script.
# Use at your own risk. No implied or specific warranties are given.
# You may change it for your own usage only
# Version 3.7.0 09.01.2022
###########################################################################
# chkconfig: 345 66 19
# description: HCL Domino Server (notes)
### BEGIN INIT INFO
# Provides: rc_domino
# Required-Start: $remote_fs $syslog $network sshd
# Required-Stop: $remote_fs $syslog
# Default-Start: 3 5
# Default-Stop: 0 1 2 6
# Short-Description: HCL Domino Server (notes)
# Description: HCL Domino Server (notes)
# Start/Stop Script V3.7.0 for xLinux/zLinux/AIX
# 2005-2022 Copyright by Daniel Nashed (domino_unix@nashcom.de)
### END INIT INFO
# Specify username for this Domino instance.
# Set default user to "notes" if no user is specified
if [ -z "$DOMINO_USER" ]; then
DOMINO_USER=notes
fi
# The following configuration could be read from config file
# But from security point of view this config belowns into a root owned file
DOMINO_START_SCRIPT=/opt/nashcom/startscript/rc_domino_script
DOMINO_SYSTEMD_NAME=domino.service
# Read configuration for service from central config file
# for multiple partions use separate file:
# . /etc/sysconfig/rc_domino_config_$DOMINO_USER
# . /etc/sysconfig/rc_domino_config
# Optional get the name from script name e.g. 'domino_myuser1"
# DOMINO_USER=`basename $0 | cut -f 2 -d _`
# VERBOSE_INFO="yes"
# Determine architecture and platform
if [ `uname` = AIX ]; then
LARCH=ibmpow
PLATFORM_NAME=AIX
elif [ `uname` = Linux ]; then
LARCH=linux
UNAME=`uname -m`
if [ $UNAME = s390 ]; then
PLATFORM_NAME=zLinux
elif [ $UNAME = s390x ]; then
PLATFORM_NAME=zLinux
else
PLATFORM_NAME=xLinux
fi
# Query linux distribution
if [ ${LARCH} = "linux" ]; then
if [ -e /etc/SuSE-release ]; then
LINUX_DISTRIBUTION=suse
elif [ -e /etc/redhat-release ]; then
LINUX_DISTRIBUTION=redhat
else
LINUX_DISTRIBUTION=unknown
fi
fi
fi
if [ ${LARCH} = "linux" ]; then
# Determine script name. for symbolic link check real name
DOMINO_SERVICE_NAME=`readlink $0`
if [ -z "$DOMINO_SERVICE_NAME" ]; then
DOMINO_SERVICE_NAME=$0
fi
DOMINO_SERVICE_NAME=`basename $DOMINO_SERVICE_NAME`
fi
# Docker Operations
# check if running inside a container
if [ -e "/.dockerenv" ]; then
DOCKER_ENV=yes
fi
# Podman has it's own name
if [ -e "/run/.containerenv" ]; then
DOCKER_ENV=yes
fi
# K8s environment
if [ -n "$KUBERNETES_SERVICE_HOST" ]; then
DOCKER_ENV=yes
fi
if [ "$DOCKER_ENV" = "yes" ]; then
# in Docker environments check LOGNAME first. If not present use whoami, which could also fail
# some environments use --user to map a name, which isn't listed in the container
# in that case use the UID
LOGNAME=`whoami 2>/dev/null`
if [ -z "$LOGNAME" ]; then
LOGNAME=`id -u`
fi
export LOGNAME
export DOMINO_USER=$LOGNAME
if [ "$LOGNAME" = "$DOMINO_USER" ]; then
$DOMINO_START_SCRIPT "$1" "$2" "$3" "$4" "$5" "$6"
else
su - $DOMINO_USER -c "$DOMINO_START_SCRIPT '$1' '$2' '$3' '$4' '$5' '$6'"
fi
exit 0
elif [ -n "$(uname -r|grep microsoft)" ]; then
# WSL does not support systemd -> Start the server directly
if [ "$LOGNAME" = "$DOMINO_USER" ]; then
$DOMINO_START_SCRIPT "$1" "$2" "$3" "$4" "$5" "$6"
else
su - $DOMINO_USER -c "$DOMINO_START_SCRIPT '$1' '$2' '$3' '$4' '$5' '$6'"
fi
exit 0
else
# normal operations
if [ -z "$LOGNAME" ]; then
export LOGNAME=`whoami`
fi
fi
# systemd operations for start/stop
if [ -e /etc/systemd/system ]; then
if [ ! -z "$DOMINO_SYSTEMD_NAME" ]; then
if [ "$LOGNAME" = "$DOMINO_USER" ]; then
SWITCH_MONITOR_COMMAND=""
else
SWITCH_MONITOR_COMMAND="su - $DOMINO_USER -c"
fi
if [ "$1" = "start" ]; then
echo Starting systemd "$DOMINO_SYSTEMD_NAME"
systemctl start "$DOMINO_SYSTEMD_NAME"
if [ "$2" = "live" ]; then
echo starting live console
$SWITCH_MONITOR_COMMAND "$DOMINO_START_SCRIPT monitor"
fi
exit 0
elif [ "$1" = "stop" ]; then
echo
echo Stopping systemd "$DOMINO_RC_NAMEDOMINO_RC_NAMEDOMINO_RC_NAMEDOMINO_SYSTEMD_NAME"
echo
if [ "$2" = "live" ]; then
systemctl stop "$DOMINO_SYSTEMD_NAME" &
echo starting live console
$SWITCH_MONITOR_COMMAND "$DOMINO_START_SCRIPT monitor"
else
systemctl stop "$DOMINO_SYSTEMD_NAME"
fi
echo
exit 0
elif [ "$1" = "restart" ]; then
if [ "$2" = "live" ]; then
echo Cannot invoke live console in combination with systemd. run 'monitor' separately
fi
echo
echo Stopping systemd "$DOMINO_SYSTEMD_NAME"
systemctl stop "$DOMINO_SYSTEMD_NAME"
echo
echo Starting systemd "$DOMINO_SYSTEMD_NAME"
systemctl start "$DOMINO_SYSTEMD_NAME"
echo
exit 0
elif [ "$1" = "restartcompact" ]; then
echo
echo Stopping systemd "$DOMINO_SYSTEMD_NAME"
systemctl stop "$DOMINO_SYSTEMD_NAME"
if [ "$LOGNAME" = "$DOMINO_USER" ]; then
$DOMINO_START_SCRIPT compact
else
su - $DOMINO_USER -c "$DOMINO_START_SCRIPT compact"
fi
echo
echo Starting systemd "$DOMINO_SYSTEMD_NAME"
systemctl start "$DOMINO_SYSTEMD_NAME"
echo
exit 0
elif [ "$1" = "restartfixup" ]; then
echo
echo Stopping systemd "$DOMINO_SYSTEMD_NAME"
systemctl stop "$DOMINO_SYSTEMD_NAME"
if [ "$LOGNAME" = "$DOMINO_USER" ]; then
$DOMINO_START_SCRIPT fixup
else
su - $DOMINO_USER -c "$DOMINO_START_SCRIPT fixup"
fi
echo
echo Starting systemd "$DOMINO_SYSTEMD_NAME"
systemctl start "$DOMINO_SYSTEMD_NAME"
echo
exit 0
elif [ "$1" = "statusd" ]; then
echo
systemctl status "$DOMINO_SYSTEMD_NAME"
echo
exit 0
elif [ "$1" = "systemlog" ]; then
if [ -z "$2" ]; then
LAST_LOG_LINES=100
else
LAST_LOG_LINES="$2"
fi
echo
echo "--- Last System Log Output ($LAST_LOG_LINES) ---"
journalctl -u $DOMINO_SYSTEMD_NAME | tail -$LAST_LOG_LINES
echo
exit 0
elif [ "$1" = "service" ]; then
echo
if [ -z "$2" ]; then
echo "Status"
systemctl status "$DOMINO_SYSTEMD_NAME"
elif [ "$2" = "status" ]; then
echo "Status"
systemctl status "$DOMINO_SYSTEMD_NAME"
elif [ "$2" = "on" ]; then
echo "Enabling Service"
systemctl enable "$DOMINO_SYSTEMD_NAME"
elif [ "$2" = "off" ]; then
echo "Disabling Service"
systemctl disable "$DOMINO_SYSTEMD_NAME"
elif [ "$2" = "add" ]; then
echo "Enabling Service"
systemctl enable "$DOMINO_SYSTEMD_NAME"
elif [ "$2" = "del" ]; then
echo "Disabling Service"
systemctl disable "$DOMINO_SYSTEMD_NAME"
else
systemctl "$2" "$DOMINO_SYSTEMD_NAME"
fi
echo
exit 0
fi
fi
fi
# -- Legacy before systemd operations --
SWITCH_USER=0
# Starting a server always needs a switch to the right run-time environment
if [ "$LOGNAME" = "$DOMINO_USER" ]; then
if [ "$1" = "start" ]; then
SWITCH_USER=1
elif [ "$1" = "restart" ]; then
SWITCH_USER=1
elif [ "$1" = "restartcompact" ]; then
SWITCH_USER=1
elif [ "$1" = "restartfixup" ]; then
SWITCH_USER=1
fi
else
SWITCH_USER=1
fi
if [ "$1" = "setenv" ]; then
echo "'setenv' can be only used directly from 'rc_domino_script' invoked with the right user"
exit 1
fi
# Special handling for CentOS/RedHat start/stop
if [ "$LINUX_DISTRIBUTION" = "redhat" ]; then
if [ "$1" = "start" ]; then
start_stop=1
elif [ "$1" = "stop" ]; then
start_stop=1
elif [ "$1" = "restart" ]; then
start_stop=1
elif [ "$1" = "restartcompact" ]; then
start_stop=1
elif [ "$1" = "restartfixup" ]; then
start_stop=1
fi
if [ "$start_stop" = "1" ]; then
if [ ! -w /var/lock/subsys ]; then
echo "On CentOS/RedHat you can only start/stop the server with root-permissions"
exit 1
fi
fi
fi
if [ "$1" = "service" ]; then
if [ "$LINUX_DISTRIBUTION" = "suse" ]; then
if [ -z "$2" ]; then
echo "Status for Service '$DOMINO_SERVICE_NAME'"
chkconfig --list "$DOMINO_SERVICE_NAME"
elif [ "$2" = "status" ]; then
echo "Status for Service '$DOMINO_SERVICE_NAME'"
chkconfig --list "$DOMINO_SERVICE_NAME"
elif [ "$2" = "on" ]; then
echo "Enabling Service '$DOMINO_SERVICE_NAME'"
chkconfig --add "$DOMINO_SERVICE_NAME"
chkconfig "$DOMINO_SERVICE_NAME" on
elif [ "$2" = "off" ]; then
echo "Disabling Service '$DOMINO_SERVICE_NAME'"
chkconfig "$DOMINO_SERVICE_NAME" off
elif [ "$2" = "add" ]; then
echo "Installing Service '$DOMINO_SERVICE_NAME'"
chkconfig --add "$DOMINO_SERVICE_NAME"
elif [ "$2" = "del" ]; then
echo "Removing Service '$DOMINO_SERVICE_NAME'"
chkconfig --del "$DOMINO_SERVICE_NAME"
else
echo "Unknown parameter '$1' for 'service'-command"
fi
elif [ "$LINUX_DISTRIBUTION" = "redhat" ]; then
if [ -z "$2" ]; then
echo "Status for Service '$DOMINO_SERVICE_NAME'"
chkconfig --list "$DOMINO_SERVICE_NAME"
elif [ "$2" = "status" ]; then
echo "Status for Service '$DOMINO_SERVICE_NAME'"
chkconfig --list "$DOMINO_SERVICE_NAME"
elif [ "$2" = "on" ]; then
echo "Enabling Service '$DOMINO_SERVICE_NAME'"
chkconfig "$DOMINO_SERVICE_NAME" on
elif [ "$2" = "off" ]; then
echo "Disabling Service '$DOMINO_SERVICE_NAME'"
chkconfig "$DOMINO_SERVICE_NAME" off
elif [ "$2" = "add" ]; then
echo "Installing Service '$DOMINO_SERVICE_NAME'"
chkconfig --add "$DOMINO_SERVICE_NAME"
elif [ "$2" = "del" ]; then
echo "Removing Service '$DOMINO_SERVICE_NAME'"
chkconfig --del "$DOMINO_SERVICE_NAME"
else
echo "Unknown parameter '$1' for 'service'-command"
fi
else
echo "Feature only supported on Linux"
exit 0
fi
exit 0
fi
# Run the main startup script
if [ "$SWITCH_USER" = "0" ]; then
$DOMINO_START_SCRIPT "$1" "$2" "$3" "$4" "$5" "$6"
else
if [ "$VERBOSE_INFO" = "yes" ]; then
echo Switching to $DOMINO_USER
fi
su - $DOMINO_USER -c "$DOMINO_START_SCRIPT '$1' '$2' '$3' '$4' '$5' '$6'"
fi
RETVAL=$?
# Special handling for CentOS/RedHat start/stop
if [ "$LINUX_DISTRIBUTION" = "redhat" ]; then
if [ -z "$DOMINO_SYSTEMD_NAME" ]; then
# Source function library.
. /etc/rc.d/init.d/functions
# Determine script name. for symbolic link check real name
if [ "$VERBOSE_INFO" = "yes" ]; then
echo "Return Code: " $RETVAL
fi
if [ "$1" = "start" ]; then
touch /var/lock/subsys/$DOMINO_SERVICE_NAME
elif [ "$1" = "restart" ]; then
touch /var/lock/subsys/$DOMINO_SERVICE_NAME
elif [ "$1" = "stop" ]; then
rm -f /var/lock/subsys/$DOMINO_SERVICE_NAME
fi
fi
fi
exit $RETVAL