Skip to content

Instantly share code, notes, and snippets.

@f440
Last active March 25, 2020 05:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save f440/be396e3ca4a73f163573b11d78500f29 to your computer and use it in GitHub Desktop.
Save f440/be396e3ca4a73f163573b11d78500f29 to your computer and use it in GitHub Desktop.
docker, shell, ruby, signal
1. docker build -t f440/test .
2. docker run --rm -ti f440/test
3. docker stop $(docker ps | grep f440/test | awk '{print $1}')
FROM alpine
RUN apk add --no-cache ruby
RUN wget -O /usr/local/bin/dumb-init https://github.com/Yelp/dumb-init/releases/download/v1.2.2/dumb-init_1.2.2_amd64
RUN chmod +x /usr/local/bin/dumb-init
ENV TINI_VERSION v0.18.0
ADD https://github.com/krallin/tini/releases/download/${TINI_VERSION}/tini-static /tini
RUN chmod +x /tini
COPY ./foo.sh /tmp/foo.sh
COPY ./foo.rb /tmp/foo.rb
ENTRYPOINT ["/tini", "--"]
CMD ["/tmp/foo.sh"]
#!/usr/bin/env ruby
puts "I have PID #{Process.pid}"
def shut_down
puts "\nShutting down gracefully..."
sleep 5
end
Signal.trap("QUIT") {
shut_down
exit
}
Signal.trap("INT") {
shut_down
exit
}
# Trap `Kill `
Signal.trap("TERM") {
shut_down
exit
}
10.times do |i|
puts i
sleep 1
end
#!/bin/sh
echo pid: $$
exec /tmp/foo.rb # 2>&1 | tee /log/foo.log
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment