Skip to content

Commit

Permalink
Merge pull request hopsoft#94 from hamelg/gha01
Browse files Browse the repository at this point in the history
Add features to the entrypoint script
  • Loading branch information
deniszh committed Mar 2, 2019
2 parents 4e5fbf7 + a3ab086 commit 80ba1ce
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 6 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,13 @@ Use `RELAY=1` environment variable to enable carbon relay instance. Use `[relay]
## Logrotate
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.

## Runit
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`.
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`...

## Startup custom scripts
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`.

## Change the Configuration

Read up on Graphite's [post-install tasks](https://graphite.readthedocs.org/en/latest/install.html#post-install-tasks).
Expand Down
53 changes: 50 additions & 3 deletions conf/entrypoint
Original file line number Diff line number Diff line change
@@ -1,9 +1,56 @@
#!/bin/sh

## Inspired from the script found at
## https://sanjeevan.co.uk/blog/running-services-inside-a-container-using-runit-and-alpine-linux/

shutdown() {
echo "shutting down container"

# first shutdown any service started by runit
for _srv in $(ls -1 /etc/service); do
sv force-stop $_srv
done

# shutdown runsvdir command
kill -HUP $RUNSVDIR
wait $RUNSVDIR

# give processes time to stop
sleep 0.5

# kill any other processes still running in the container
for _pid in $(ps -eo pid | grep -v PID | tr -d ' ' | grep -v '^1$' | head -n -6); do
timeout -t 5 /bin/sh -c "kill $_pid && wait $_pid || kill -9 $_pid"
done
exit
}

. /opt/graphite/bin/activate

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

runsvdir -P /etc/service
# run all scripts in the run_once folder
[ -d /etc/run_once ] && /bin/run-parts /etc/run_once

## check services to disable
for _srv in $(ls -1 /etc/service); do
eval X=$`echo -n $_srv | tr [:lower:]- [:upper:]_`_DISABLED
[ -n "$X" ] && touch /etc/service/$_srv/down
done

exec runsvdir -P /etc/service &

RUNSVDIR=$!
echo "Started runsvdir, PID is $RUNSVDIR"
echo "wait for processes to start...."

sleep 5
for _srv in $(ls -1 /etc/service); do
sv status $_srv
done

# catch shutdown signals
trap shutdown SIGTERM SIGHUP SIGQUIT SIGINT
wait $RUNSVDIR

shutdown
1 change: 0 additions & 1 deletion conf/etc/service/carbon-aggregator/run
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/bin/sh

rm -f /opt/graphite/storage/carbon-aggregator-a.pid
exec python3 /opt/graphite/bin/carbon-aggregator.py start --debug 2>&1
1 change: 0 additions & 1 deletion conf/etc/service/carbon-relay/run
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@

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

rm -f /opt/graphite/storage/carbon-relay-a.pid
exec python3 /opt/graphite/bin/carbon-relay.py start --debug 2>&1
1 change: 0 additions & 1 deletion conf/etc/service/carbon/run
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/bin/sh

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

0 comments on commit 80ba1ce

Please sign in to comment.