Last active
July 18, 2023 11:34
-
-
Save rennex/f379b8a53c8f2791d5838b4622ed6dd8 to your computer and use it in GitHub Desktop.
Example of a systemd service file to start a Sinatra 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
# /etc/systemd/system/foo.service | |
[Unit] | |
Description=Foo service | |
Wants=nginx.service | |
Requires=postgresql.service | |
After=postgresql.service | |
[Service] | |
Type=simple | |
User=foo | |
Group=foo | |
ExecStart=/srv/foo/app/serve | |
Restart=always | |
TimeoutSec=10 | |
[Install] | |
WantedBy=multi-user.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
# /etc/nginx/sites-enabled/foo | |
# example nginx config, which proxies /foo to this app | |
server { | |
# ...basic stuff omitted... | |
location / { | |
try_files $uri $uri/ =404; | |
} | |
location /foo { | |
# this nginxroot directory has "foo" symlinked to /srv/foo/app/public | |
# to avoid having to rewrite that prefix out here :) | |
root /srv/foo/nginxroot; | |
try_files $uri @foosinatra; | |
} | |
location @foosinatra { | |
include /etc/nginx/sinatra_params; | |
proxy_pass http://localhost:1234; | |
} | |
} |
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 | |
cd $(dirname $(readlink -f "$0")) | |
rackup --env production -o 127.0.0.1 -p 1234 >>log/production.log 2>&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
# /etc/nginx/sinatra_params | |
# extra headers that seem to be needed for Sinatra apps, especially when nginx uses https | |
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | |
proxy_set_header X-Forwarded-Proto $scheme; | |
proxy_set_header X-Forwarded-Host $host; | |
proxy_set_header Host $http_host; | |
proxy_set_header Connection ""; | |
proxy_http_version 1.1; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
And I guess I'll have to put extra info here. foo.service goes to /etc/systemd/system/foo.service (at least in Ubuntu 16.04). Run
systemctl daemon-reload
,systemctl start foo
.systemctl enable foo
to make it autostart on boot.