Last active
March 25, 2020 05:00
-
-
Save f440/be396e3ca4a73f163573b11d78500f29 to your computer and use it in GitHub Desktop.
docker, shell, ruby, signal
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1. docker build -t f440/test . | |
2. docker run --rm -ti f440/test | |
3. docker stop $(docker ps | grep f440/test | awk '{print $1}') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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