-
-
Save igkuz/87d2087ccf333870c50cbc04ebfedf04 to your computer and use it in GitHub Desktop.
Socket Activation systemd service with Unicorn & Nginx
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
require 'bundler/setup' | |
Bundler.require | |
require 'rack' | |
app = Proc.new do |env| | |
['200', {'Content-Type' => 'text/html'}, ['Simple app for test']] | |
end | |
run app |
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 ruby:2.4 | |
RUN mkdir /app | |
COPY Gemfile Gemfile.lock /app/ | |
WORKDIR /app | |
RUN bundle install | |
ADD config.ru /app/ | |
ADD unicorn.rb /app/ | |
CMD ["bundle", "exec", "--keep-file-descriptors", "unicorn", "-c", "unicorn.rb"] |
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
source 'https://rubygems.org' | |
gem 'unicorn' | |
gem 'rack' |
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
GEM | |
remote: https://rubygems.org/ | |
specs: | |
kgio (2.11.2) | |
rack (2.0.5) | |
raindrops (0.19.0) | |
unicorn (5.4.0) | |
kgio (~> 2.6) | |
raindrops (~> 0.7) | |
PLATFORMS | |
ruby | |
DEPENDENCIES | |
rack | |
unicorn | |
BUNDLED WITH | |
1.16.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
[Unit] | |
Description=Socket Activation with Unicorn Service | |
After=network.target sact-test.socket | |
Requires=sact-test.socket | |
[Service] | |
ExecStart=/usr/bin/docker run --user 1001 --rm --name sact-test-n -v '/apps/sact/sact-git/tmp:/app/tmp' -e 'SOCKET_FILE=/app/tmp/sockets/unicorn.sock' sact-test | |
ExecStartPost=/bin/sleep 1 | |
SyslogIdentifier=sact-test-docker | |
ExecStop=/usr/bin/docker stop sact-test-n |
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
[Unit] | |
Requires=sact-test-docker.service | |
After=sact-test-docker.service | |
[Service] | |
SyslogIdentifier=sact-test-docker | |
ExecStart=/lib/systemd/systemd-socket-proxyd /apps/sact/sact-git/tmp/sockets/unicorn.sock |
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
[Unit] | |
Description=Socket Activation with Unicorn | |
PartOf=sact-test.service | |
[Socket] | |
SocketUser=sact | |
SocketGroup=sact | |
SocketMode=0777 | |
Backlog=2048 | |
ListenStream=/apps/sact/sact-git/tmp/sockets/unicorn-proxy.sock | |
[Install] | |
WantedBy=sockets.target |
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
upstream app_sact { | |
server unix:/apps/sact/sact-git/tmp/sockets/unicorn-proxy.sock; | |
} | |
server { | |
listen 80; | |
charset utf-8; | |
set $application_name "sact"; | |
location / { | |
try_files $uri $uri.html @application; | |
} | |
location @application { | |
proxy_set_header Host $host; | |
proxy_set_header X-Real-IP $remote_addr; | |
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | |
proxy_set_header X-Forwarded-Proto $scheme; | |
proxy_hide_header X-User-Id; | |
proxy_redirect off; | |
proxy_pass http://app_$application_name; | |
break; | |
} | |
} |
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
worker_processes 2 | |
timeout 30 | |
listen ENV['SOCKET_FILE'] || 8080, backlog: 2048 | |
working_directory ENV['APP_PATH'] || '/app/' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment