-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathrc_domino
executable file
·304 lines (245 loc) · 7.27 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
#!/bin/bash
# change this to #!/bin/ksh for AIX
###########################################################################
# RC RunLevel Entry Point
###########################################################################
# Start/Stop Script for Domino on Linux & AIX
# 2005-2024 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 4.0.1 07.08:2024
###########################################################################
# 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 V4.0.0 for Linux & AIX
# 2005-2023 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
else
LARCH=linux
PLATFORM_NAME=xLinux
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
if [ -z "$LOGNAME" ]; then
LOGNAME=$(whoami 2>/dev/null)
if [ -z "$LOGNAME" ]; then
LOGNAME=$(id -u)
fi
export LOGNAME
fi
if [ -z "$DOMINO_USER" ]; then
export DOMINO_USER=$LOGNAME
fi
# Check if sudo is requested or fall back in case of error
SUDO()
{
local RET=
if [ "$EUID" = 0 ]; then
"$@"
return 0
fi
if [ -z "$DOMINO_NO_SUDO" ]; then
sudo "$@"
RET="$?"
if [ "$RET" = "0" ]; then
return 0
fi
if [ "$RET" = "9" ]; then
return 0
fi
echo
echo "Info: export DOMINO_NO_SUDO=1 or enable sudo $DOMINO_USER for systemctl"
echo
fi
"$@"
}
# If no systemd is running start server directly (Docker, Podman, K8s, WSL)
if [ "$LARCH" = "linux" ]; then
if [ -z "$(ps --no-headers -o comm 1 | grep systemd)" ]; then
export DOMINO_SYSTEMD_NAME=
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
fi
fi
# systemd operations for start/stop
if [ -e /etc/systemd/system ]; then
if [ -n "$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"
SUDO 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_SYSTEMD_NAME"
echo
if [ "$2" = "live" ]; then
SUDO systemctl stop "$DOMINO_SYSTEMD_NAME" &
echo starting live console
$SWITCH_MONITOR_COMMAND "$DOMINO_START_SCRIPT monitor"
else
SUDO 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"
SUDO systemctl stop "$DOMINO_SYSTEMD_NAME"
echo
echo Starting systemd "$DOMINO_SYSTEMD_NAME"
SUDO systemctl start "$DOMINO_SYSTEMD_NAME"
echo
exit 0
elif [ "$1" = "restartcompact" ]; then
echo
echo Stopping systemd "$DOMINO_SYSTEMD_NAME"
SUDO 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"
SUDO systemctl start "$DOMINO_SYSTEMD_NAME"
echo
exit 0
elif [ "$1" = "restartfixup" ]; then
echo
echo Stopping systemd "$DOMINO_SYSTEMD_NAME"
SUDO 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"
SUDO 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
case "$2" in
"")
echo "Status"
systemctl status "$DOMINO_SYSTEMD_NAME"
;;
status)
echo "Status"
systemctl status "$DOMINO_SYSTEMD_NAME"
;;
on|add|enable)
echo "Enabling Service"
SUDO systemctl enable "$DOMINO_SYSTEMD_NAME"
;;
off|del|disable)
echo "Disabling Service"
SUDO systemctl disable "$DOMINO_SYSTEMD_NAME"
;;
*)
systemctl "$2" "$DOMINO_SYSTEMD_NAME"
;;
esac
echo
exit 0
fi
fi
fi
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
# 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
SUDO su - $DOMINO_USER -c "$DOMINO_START_SCRIPT '$1' '$2' '$3' '$4' '$5' '$6'"
fi
RETVAL=$?
exit $RETVAL