Repository navigation
Expand file tree
/
Copy pathtrafficserver.in
More file actions
515 lines (476 loc) · 17.9 KB
/
Copy pathtrafficserver.in
File metadata and controls
515 lines (476 loc) · 17.9 KB
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
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
#!/bin/sh
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You 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.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# chkconfig: - 90 10
# description: Apache Traffic Server is a fast, scalable and extensible \
# HTTP/1.1 and HTTP/2 compliant caching proxy server.
# processname: traffic_server
# config: /etc/trafficserver
# config: /etc/sysconfig/trafficserver
#
# Template from /etc/init.d/skeleton on Ubuntu
#
### BEGIN INIT INFO
# Provides: Traffic Server
# Required-Start: $local_fs $remote_fs
# Required-Stop: $local_fs $remote_fs
# Default-Start: 2 3 4 5
# Default-Stop: S 0 1 6
# Short-Description: Startup/shutdown script for the Apache Traffic Server
# Description: Apache Traffic Server is fast, scalable and extensible
# HTTP/1.1 compliant caching proxy server.
### END INIT INFO
# Fedora:
# When this file is installed as /etc/rc.d/init.d/trafficserver
# and added to the chkconfig system with `chkconfig --add trafficserver`
# then the default values of these variables can be overridden
# in the /etc/sysconfig/trafficserver file
# Ubuntu:
# Values read from /etc/default/trafficserver
TS_PACKAGE_NAME="@PACKAGE_NAME@"
TS_PACKAGE_VERSION="@PACKAGE_VERSION@"
TS_PACKAGE_BUGREPORT="@PACKAGE_BUGREPORT@"
UNAME_S=$(uname -s)
if [ -e /etc/SuSE-release ]; then
DISTRIB_ID="suse"
elif [ -e /etc/fedora-release ]; then
DISTRIB_ID="fedora"
elif [ -e /etc/gentoo-release ]; then
DISTRIB_ID="gentoo"
elif [ -e /etc/redhat-release ]; then
DISTRIB_ID="redhat" # also exists on Fedora
elif [ -e /etc/lsb-release ]; then
DISTRIB_ID="ubuntu"
elif [ -e /etc/debian_version ]; then
DISTRIB_ID="debian" # also exists on Ubuntu
elif [ -e /etc/slackware-version ]; then
DISTRIB_ID="slackware"
elif [ "$UNAME_S" = "Darwin" ]; then
DISTRIB_ID="Darwin"
elif [ "$UNAME_S" = "FreeBSD" ]; then
DISTRIB_ID="FreeBSD"
elif nixos-version > /dev/null; then
DISTRIB_ID="nixos"
fi
# We might want to move over to use /etc/system-release for more distros?
# I know at least Fedora supports it as well.
if [ "" = "$DISTRIB_ID" -a -e /etc/system-release ]; then
case $(cat /etc/system-release) in
*Amazon*)
DISTRIB_ID="redhat" # Amazon AMI is mostly like RHEL
;;
*)
;;
esac
fi
# /usr/bin/lsb_release -rd # Ubuntu release & description info
HEAD=/usr/bin/head
test -x $HEAD || HEAD=head
ESED=/usr/bin/sed
test -x $ESED || ESED=sed
# Ubuntu: Do NOT "set -e"
#Ubuntu:PATH should only include /usr/* if it runs after the mountnfs.sh script
test "$DISTRIB_ID" != nixos && PATH=/usr/sbin:/usr/bin:/sbin:/bin
DESC="start/stop Traffic Server"
NAME=trafficserver
SLEEP_TIME=5
TS_PREFIX="@prefix@"
TS_ROOT=${TS_ROOT:-$TS_PREFIX}
# ####################################
# run root is not used by default
# set this value if using a custom layout structure
# TS_RUNROOT=""
# TS_BASE is offset inside the file system from where the layout starts
# For standard installations TS_BASE will be empty
eval TS_BASE="`echo $TS_ROOT | ${ESED} -e 's;@prefix@$;;'`"
TS_NAME=${TS_NAME:-traffic_server}
TS_DAEMON=${TS_DAEMON:-$TS_BASE@exp_bindir@/traffic_server}
TS_DAEMON_ARGS=""
TC_BINARY=${TC_BINARY:-$TS_BASE@exp_bindir@/traffic_ctl}
TY_BINARY=${TC_BINARY:-$TS_BASE@exp_bindir@/traffic_layout}
TS_PIDFILE=${TS_PIDFILE:-$TS_BASE@exp_runtimedir@/server.lock}
# number of times to retry check on pid lock file
PIDFILE_CHECK_RETRIES=${PIDFILE_CHECK_RETRIES:-30}
# stdout file of executable
STDOUTLOG=${STDOUTLOG:-$TS_BASE@exp_logdir@/traffic.out}
# stderr file of executable
STDERRLOG=${STDERRLOG:-$TS_BASE@exp_logdir@/traffic.out}
# hooks
RC_START_HOOK=${RC_START_HOOK:-$TS_BASE@exp_bindir@/rc_start_hook.sh}
RC_RELOAD_HOOK=${RC_PRELOAD_HOOK:-$TS_BASE@exp_bindir@/rc_reload_hook.sh}
if [ -d /etc/rc.d/init.d ]; then
SCRIPTNAME=/etc/rc.d/init.d/$NAME # Fedora
elif [ -d /etc/init.d ]; then
SCRIPTNAME=/etc/init.d/$NAME # Ubuntu
elif [ "$DISTRIB_ID" = "Darwin" ]; then
SCRIPTNAME=$0 # Darwin
elif [ "$DISTRIB_ID" = "FreeBSD" ]; then
SCRIPTNAME=$0 # FreeBSD
elif [ "$DISTRIB_ID" = "nixos" ]; then
SCRIPTNAME=$0 # NixOS
echo "Warn: Use of this script is not recommended on NixOS. Instead, enable the module"
echo " 'services.trafficserver' and use systemctl to control Traffic Server."
else
echo "This script needs to be ported to this OS"
exit 1
fi
# Exit if the package can not be found
if [ ! -x "$TS_DAEMON" ]; then
echo "Error: Can not find $TS_DAEMON using TS_ROOT=$TS_ROOT"
echo " Please set TS_ROOT to point to base installation."
exit 0
fi
# Ubuntu: Read configuration variable file if it is present
test -r /etc/default/$NAME && . /etc/default/$NAME
# RHEL/Fedora: Read configuration variable file if it is present
test -r /etc/sysconfig/$NAME && . /etc/sysconfig/$NAME
# Gentoo: Read configuration variable file if it is present
test -r /etc/conf.d/$NAME && . /etc/conf.d/$NAME
# Ubuntu: Load the VERBOSE setting and other rcS variables
test -f /etc/default/rcS && . /etc/default/rcS
# Suse: load rc.status
test -f /etc/rc.status && . /etc/rc.status
# Fedora: make avail helper functions 'action', 'killproc', 'status', etc
test -f /etc/rc.d/init.d/functions && . /etc/rc.d/init.d/functions
# Gentoo: make avail helper function 'ebegin', 'eend', etc
test -f /etc/init.d/functions.sh && . /etc/init.d/functions.sh
# Ubuntu: Define LSB log_* functions.
# Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
test -f /lib/lsb/init-functions && . /lib/lsb/init-functions
# FreeBSD
# NB: FreeBSD's ports system installs a run script in /usr/local/etc/rc.d/
# with native OS rc.subr(8) features.
test -f /etc/rc.subr && . /etc/rc.subr
if [ ! -d $TS_BASE@exp_runtimedir@ ]; then
mkdir -p $TS_BASE@exp_runtimedir@
chown @pkgsysuser@:@pkgsysgroup@ $TS_BASE@exp_runtimedir@
fi
#
# Fedora/NixOS:
# launches $* in the background
# and checks if program creates its own pid lock file
# redirects stdout and stderr to files
# this function is meant to substitute 'daemon'
# because 'daemon' expects $1 to fork itself
forkdaemon()
{
local i=0
# launch in background, i.e. fork
# and redirect stdout and stderr to files
$* --bind_stdout $STDOUTLOG --bind_stderr $STDERRLOG >> $STDOUTLOG 2>> $STDERRLOG &
while (( $i < $PIDFILE_CHECK_RETRIES ))
do
# check for regular file and size greater than 0
if [[ -f $TS_PIDFILE ]] && [[ -s $TS_PIDFILE ]]; then
success
return 0
fi
sleep 1 # zzz for 1 second
(( i++ ))
done
failure || true
return 1
}
#
# Ubuntu: Function that starts the daemon/service
#
do_start()
{
# Return
# 0 if daemon has been started
# 1 if daemon was already running
# 2 if daemon could not be started
start-stop-daemon --start --quiet --pidfile $TS_PIDFILE --exec $TS_DAEMON --test > /dev/null \
|| return 1
start-stop-daemon --start --background --quiet --pidfile $TS_PIDFILE --exec $TS_DAEMON -- \
$TS_DAEMON_ARGS \
|| return 2
# Add code here, if necessary, that waits for the process to be ready
# to handle requests from services started subsequently which depend
# on this one. As a last resort, sleep for some time.
sleep 1
test -f "$TS_PIDFILE" || return 2
}
#
# Ubuntu: Function that stops the daemon/service
#
do_stop()
{
# Return
# 0 if daemon has been stopped
# 1 if daemon was already stopped
# 2 if daemon could not be stopped
# other if a failure occurred
start-stop-daemon --stop --quiet --retry=QUIT/30/KILL/5 --pidfile $TS_PIDFILE --name '[TS_MAIN]'
RETVAL="$?"
test "$RETVAL" != 0 && return $RETVAL
# Wait for children to finish too if this is a daemon that forks
# and if the daemon is only ever run from this initscript.
# If the above conditions are not satisfied then add some other code
# that waits for the process to drop all resources that could be
# needed by services started subsequently. A last resort is to
# sleep for some time.
start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $TS_DAEMON
RETVAL="$?"
test "$RETVAL" != 0 && return $RETVAL
# Need to stop the TS
start-stop-daemon --stop --quiet --oknodo --retry=QUIT/30/KILL/5 --pidfile $TS_PIDFILE --name '[TS_MAIN]'
RETVAL="$?"
test "$RETVAL" != 0 && return $RETVAL
# Many daemons don't delete their pidfiles when they exit.
rm -f $TS_PIDFILE
return "$RETVAL"
}
rc_reload_hook()
{
if [ ! -x "$RC_RELOAD_HOOK" ]; then
return 0
fi
sh $RC_RELOAD_HOOK
return $?
}
rc_start_hook()
{
if [ ! -x "$RC_START_HOOK" ]; then
return 0
fi
sh $RC_START_HOOK
return $?
}
# Make sure the NOFILES limit is set high in case this process is not
# started from a logged in prompt
ulimit -n 500000
# main
case "$1" in
start)
rc_start_hook
retval="$?"
if [ "$retval" != 0 ]; then
echo "precondition was not met: ${RC_START_HOOK}"
exit "$retval"
fi
if [ "$DISTRIB_ID" = "ubuntu" -o "$DISTRIB_ID" = "debian" ] ; then
test "x$VERBOSE" != "xno" && log_daemon_msg "Starting ${TS_PACKAGE_NAME}" "$NAME"
retval=0
do_start
test "$?" -ne 0 -a "$?" -ne 1 && retval=1
test "x$VERBOSE" != "xno" && log_end_msg "$retval"
exit "$retval"
elif [ "$DISTRIB_ID" = "gentoo" ]; then
ebegin "Starting ${TS_PACKAGE_NAME}"
do_start
eend $?
elif [ "$DISTRIB_ID" = "fedora" -o "$DISTRIB_ID" = "redhat" ]; then
action "Starting ${TS_PACKAGE_NAME}:" forkdaemon $TS_DAEMON $TS_DAEMON_ARGS
elif [ "$DISTRIB_ID" = "suse" ]; then
echo -n "Starting ${TS_PACKAGE_NAME}"
startproc -p $TS_PIDFILE $TS_DAEMON $TS_DAEMON_ARGS
rc_status -v
elif [ "$DISTRIB_ID" = "nixos" ]; then
echo "Starting ${TS_PACKAGE_NAME}"
forkdaemon $TM_DAEMON $TM_DAEMON_ARGS
elif [ "$DISTRIB_ID" = "Darwin" ]; then
echo "Starting ${TS_PACKAGE_NAME}"
launchctl bsexec / launchctl list $TS_NAME > /dev/null 2>&1 && exit 0
launchctl bsexec / launchctl submit -l $TS_NAME -p $TS_DAEMON -o $STDOUTLOG -e $STDERRLOG -- $TS_DAEMON_ARGS
elif [ "$DISTRIB_ID" = "FreeBSD" ]; then
echo "Starting ${TS_PACKAGE_NAME}"
name="$TS_NAME"
command="/usr/sbin/daemon"
command_args="-o $STDOUTLOG $TS_DAEMON $TS_DAEMON_ARGS"
pidfile="$TS_PIDFILE"
run_rc_command "$1"
else
echo "This script needs to be ported to this OS"
exit 1
fi
;;
stop)
if [ "$DISTRIB_ID" = "ubuntu" -o "$DISTRIB_ID" = "debian" ] ; then
test "x$VERBOSE" != "xno" && log_daemon_msg "Stopping ${TS_PACKAGE_NAME}" "$NAME"
retval=0
do_stop
test "$?" -ne 0 -a "$?" -ne 1 && retval=1
test "x$VERBOSE" != "xno" && log_end_msg "$retval"
exit "$retval"
elif [ "$DISTRIB_ID" = "fedora" -o "$DISTRIB_ID" = "redhat" ]; then
action "Stopping ${TS_NAME}:" killproc -p $TS_PIDFILE -d 35 $TS_DAEMON
elif [ "$DISTRIB_ID" = "gentoo" ]; then
ebegin "Stopping ${TS_PACKAGE_NAME}"
do_stop
eend $?
elif [ "$DISTRIB_ID" = "suse" ]; then
echo -n "Stopping ${TS_NAME}"
killproc -p $TS_PIDFILE $TS_DAEMON
rc_status -v
elif [ "$DISTRIB_ID" = "nixos" ]; then
echo "Stopping ${TS_PACKAGE_NAME}"
if [ -e "$TM_PIDFILE" ]; then
kill $(cat $TM_PIDFILE)
rm -f ${TM_PIDFILE}
fi
if [ -e "$TS_PIDFILE" ]; then
kill $(cat $TS_PIDFILE)
rm -f ${TS_PIDFILE}
fi
elif [ "$DISTRIB_ID" = "Darwin" ]; then
echo "Stopping ${TS_PACKAGE_NAME}"
launchctl bsexec / launchctl list $TS_NAME > /dev/null 2>&1 || exit 0
echo "Stopping ${TS_NAME}"
launchctl bsexec / launchctl remove ${TS_NAME}
rm -f ${TS_PIDFILE}
elif [ "$DISTRIB_ID" = "FreeBSD" ]; then
echo "Stopping ${TS_PACKAGE_NAME}"
if [ -e "$TS_PIDFILE" ]; then
kill $(cat $TS_PIDFILE)
rm -f ${TS_PIDFILE}
fi
else
echo "This script needs to be ported to this OS"
exit 1
fi
;;
reload|force-reload)
rc_reload_hook
retval="$?"
if [ "$retval" != 0 ]; then
echo "precondition was not met: ${RC_RELOAD_HOOK}"
exit "$retval"
fi
if [ "$DISTRIB_ID" = "ubuntu" -o "$DISTRIB_ID" = "debian" ] ; then
test "x$VERBOSE" != "xno" && log_daemon_msg "Reloading ${TS_PACKAGE_NAME}" "$NAME"
retval=0
$TC_BINARY config reload
test "$?" -ne 0 -a "$?" -ne 1 && retval=1
test "x$VERBOSE" != "xno" && log_end_msg "$retval"
exit "$retval"
elif [ "$DISTRIB_ID" = "fedora" -o "$DISTRIB_ID" = "redhat" ]; then
action "Reloading ${NAME}:" $TC_BINARY config reload
elif [ "$DISTRIB_ID" = "gentoo" ]; then
ebegin "Reloading ${NAME}"
$TC_BINARY config reload
eend $?
elif [ "$DISTRIB_ID" = "suse" ]; then
echo -n "Reloading ${NAME}"
$TC_BINARY config reload
rc_status -v
elif [ "$DISTRIB_ID" = "nixos" ]; then
echo "Reloading ${NAME}"
$TL_BINARY config reload
elif [ "$DISTRIB_ID" = "Darwin" ]; then
echo "Reloading ${NAME}"
$TC_BINARY config reload
elif [ "$DISTRIB_ID" = "FreeBSD" ]; then
echo "Reloading ${NAME}"
$TC_BINARY config reload
else
echo "This script needs to be ported to this OS"
exit 1
fi
;;
restart)
if [ "$DISTRIB_ID" = "ubuntu" -o "$DISTRIB_ID" = "debian" ] ; then
#
# If the "reload" option is implemented then remove the
# 'force-reload' alias
#
log_daemon_msg "Restarting ${TS_PACKAGE_NAME}" "$NAME"
do_stop
case "$?" in
0|1)
sleep $SLEEP_TIME
do_start
case "$?" in
0) log_end_msg 0 ;;
1) log_end_msg 0 ;; # Daemons were already stopped
*) log_end_msg 1 ;; # Failed to start
esac
;;
*)
# Failed to stop
log_end_msg 1
;;
esac
else
# This is the typical process for restart
sh $0 'stop'
sleep $SLEEP_TIME
sh $0 'start'
fi
;;
status)
if [ "$DISTRIB_ID" = "fedora" -o "$DISTRIB_ID" = "redhat" ]; then
status -p $TS_PIDFILE $TS_NAME
elif [ "$DISTRIB_ID" = "ubuntu" -o "$DISTRIB_ID" = "debian" ] ; then
status_of_proc "$TS_DAEMON" "$TS_NAME" -p "$TS_PIDFILE" && exit 0 || exit $?
elif [ "$DISTRIB_ID" = "suse" ]; then
echo -n "Checking for service ${DM}: "
checkproc -p $TS_PIDFILE $TS_NAME
rc_status -v
elif [ "$DISTRIB_ID" = "Darwin" ]; then
/bin/echo -n "${TS_PACKAGE_NAME} is "
launchctl bsexec / launchctl list $TS_NAME > /dev/null 2>&1
status=$?
[ $status -eq 0 ] || /bin/echo -n "not "
echo "running."
elif [ "$DISTRIB_ID" = "FreeBSD" -o "$DISTRIB_ID" = "gentoo" -o "$DISTRIB_ID" = "nixos" ]; then
if pgrep $TS_NAME > /dev/null ; then
echo "$TS_NAME running as pid `cat $TS_PIDFILE`"; else
echo "$TS_NAME not running"
fi
exit $status
else
echo "This script needs to be ported to this OS"
exit 1
fi
;;
condrestart)
if [ "$DISTRIB_ID" = "fedora" -o "$DISTRIB_ID" = "redhat" ]; then
if $0 'status'
then
sh $0 'stop'
sh $0 'start'
fi
else
echo "This script needs to be ported to this OS"
exit 1
fi
;;
*)
if [ "$DISTRIB_ID" = "ubuntu" -o "$DISTRIB_ID" = "debian" ] ; then
echo "Usage: $SCRIPTNAME {start|stop|status|restart}" >&2
elif [ "$DISTRIB_ID" = "fedora" -o "$DISTRIB_ID" = "redhat" ]; then
echo "Usage: $0 {start|stop|status|restart|condrestart}"
elif [ "$DISTRIB_ID" = "gentoo" ]; then
echo "Usage: $0 {start|stop|reload|restart|status}"
elif [ "$DISTRIB_ID" = "suse" ]; then
echo "Usage: $0 {start|stop|restart|status}"
elif [ "$DISTRIB_ID" = "nixos" ]; then
echo "Usage: $0 {start|stop|reload|restart|status}"
elif [ "$DISTRIB_ID" = "Darwin" ]; then
echo "Usage: $0 {start|stop|restart|status}"
elif [ "$DISTRIB_ID" = "FreeBSD" ]; then
echo "Usage: $0 Usage: (start|stop|restart|status)"
echo "NB: FreeBSD's ports system installs a rc script in"
echo "/usr/local/etc/rc.d/ with native rc.subr(8) features."
else
echo "This script needs to be ported to this OS"
exit 1
fi
exit 3
;;
esac