Skip to content

Instantly share code, notes, and snippets.

@twtw
Last active April 12, 2017 14:34
Show Gist options
  • Save twtw/5494223 to your computer and use it in GitHub Desktop.
Save twtw/5494223 to your computer and use it in GitHub Desktop.
using rvm and create ruby app startup script at systemd
# create systemd service file for rails 2.3.x startup
[Unit]
Description=rails 2.3.x web server
[Service]
Type=simple
RemainAfterExit=yes
User=username
PIDFile=/home/username/WEBSERVER/tmp/pids/thin.pid
WorkingDirectory=/home/username/WEBSERVER
ExecStart=/home/username/bin/start_backup.sh
ExecStop=/home/username/.rvm/bin/backup-ror_thin -c /home/username/WEBSERVER stop
TimeoutSec=300
[Install]
WantedBy=multi-user.target
#!/bin/sh
# for rails 2.3.x start script
# backup-ror_thin is created by the command:
# rvm wrapper ruby-1.9.3-p392@default backup-ror thin
export LC_CTYPE=en_US.UTF-8
cd /home/username/RAILS/backup
/home/username/.rvm/bin/backup-ror_thin start -d
# create systemd service file for sinatra startup
# 0. rvm use ruby-2.0.0-p0@default
# 1. rvm wrapper ruby@default [webserver] thin --> generate a ~/.rvm/bin/webserver_thin file
# 2. create /etc/systemd/system/webserver.service
# 3. systemctl enable webserver
# 4. systemctl start webserver
[Unit]
Description=Ruby web server
[Service]
Type=simple
RemainAfterExit=yes
User=username
PIDFile=/home/username/WEBSERVER/logs/thin.pid
WorkingDirectory=/home/username/WEBSERVER
ExecStart=/home/username/.rvm/bin/webserver_thin -C /home/username/WEBSERVER/config.yml -c /home/username/WEBSERVER start
ExecStop=/home/username/.rvm/bin/webserver_thin -C /home/username/WEBSERVER/config.yml -R /home/username/WEBSERVER/config.ru stop
TimeoutSec=300
[Install]
WantedBy=multi-user.target
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment