Skip to content

Commit 80ba1ce

Browse files
authored
Merge pull request hopsoft#94 from hamelg/gha01
Add features to the entrypoint script
2 parents 4e5fbf7 + a3ab086 commit 80ba1ce

File tree

5 files changed

+57
-6
lines changed

5 files changed

+57
-6
lines changed

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,13 @@ Use `RELAY=1` environment variable to enable carbon relay instance. Use `[relay]
170170
## Logrotate
171171
By default logs are rotated daily, using built-in `/etc/periodic/daily/logrotate` script. Please note, that according to Docker [logging best practices](https://success.docker.com/article/logging-best-practices) "Ideally, applications log to stdout/stderr, and Docker sends those logs to the configured logging destination.". You can use `-` as log file name for such behaviour.
172172

173+
## Runit
174+
Each service started and controlled by runit will be gracefully shutdown when stopping the container : wait up to 7 seconds for the service to become down, then it will be killed. The runit environment variable `$SVWAIT` overrides this default timeout. Additionnally, a global timeout can be also specified with the docker-run option `--stop-timeout`.
175+
Each service started by default can be disabled by setting an environment variable named as : `$<service name>_DISABLED`. For instance : `CARBON_AGGREGATOR_DISABLED=1`, `STATSD_DISABLED=1`...
176+
177+
## Startup custom scripts
178+
At startup, entrypoint will run all scripts found in the directory /etc/run_once. It can be mounted with a docker-run option like this : `--mount type=bind,source=/path/to/run_once,destination=/etc/run_once`.
179+
173180
## Change the Configuration
174181

175182
Read up on Graphite's [post-install tasks](https://graphite.readthedocs.org/en/latest/install.html#post-install-tasks).

conf/entrypoint

Lines changed: 50 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,56 @@
11
#!/bin/sh
22

3+
## Inspired from the script found at
4+
## https://sanjeevan.co.uk/blog/running-services-inside-a-container-using-runit-and-alpine-linux/
5+
6+
shutdown() {
7+
echo "shutting down container"
8+
9+
# first shutdown any service started by runit
10+
for _srv in $(ls -1 /etc/service); do
11+
sv force-stop $_srv
12+
done
13+
14+
# shutdown runsvdir command
15+
kill -HUP $RUNSVDIR
16+
wait $RUNSVDIR
17+
18+
# give processes time to stop
19+
sleep 0.5
20+
21+
# kill any other processes still running in the container
22+
for _pid in $(ps -eo pid | grep -v PID | tr -d ' ' | grep -v '^1$' | head -n -6); do
23+
timeout -t 5 /bin/sh -c "kill $_pid && wait $_pid || kill -9 $_pid"
24+
done
25+
exit
26+
}
27+
328
. /opt/graphite/bin/activate
429

5-
# Ensure /usr/local/bin is in PATH. On some
6-
# weird platforms,this might not be the case
730
PATH="${PATH}:/usr/local/bin"
831

9-
runsvdir -P /etc/service
32+
# run all scripts in the run_once folder
33+
[ -d /etc/run_once ] && /bin/run-parts /etc/run_once
34+
35+
## check services to disable
36+
for _srv in $(ls -1 /etc/service); do
37+
eval X=$`echo -n $_srv | tr [:lower:]- [:upper:]_`_DISABLED
38+
[ -n "$X" ] && touch /etc/service/$_srv/down
39+
done
40+
41+
exec runsvdir -P /etc/service &
42+
43+
RUNSVDIR=$!
44+
echo "Started runsvdir, PID is $RUNSVDIR"
45+
echo "wait for processes to start...."
46+
47+
sleep 5
48+
for _srv in $(ls -1 /etc/service); do
49+
sv status $_srv
50+
done
51+
52+
# catch shutdown signals
53+
trap shutdown SIGTERM SIGHUP SIGQUIT SIGINT
54+
wait $RUNSVDIR
55+
56+
shutdown
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
#!/bin/sh
22

3-
rm -f /opt/graphite/storage/carbon-aggregator-a.pid
43
exec python3 /opt/graphite/bin/carbon-aggregator.py start --debug 2>&1

conf/etc/service/carbon-relay/run

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,4 @@
22

33
[[ -n "${RELAY}" ]] || exit 1
44

5-
rm -f /opt/graphite/storage/carbon-relay-a.pid
65
exec python3 /opt/graphite/bin/carbon-relay.py start --debug 2>&1

conf/etc/service/carbon/run

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
#!/bin/sh
22

3-
rm -f /opt/graphite/storage/carbon-cache-a.pid
43
exec python3 /opt/graphite/bin/carbon-cache.py start --debug 2>&1

0 commit comments

Comments
 (0)