Pebble Coding

ソフトウェアエンジニアによるIT技術、数学の備忘録

railsアプリをunicornでCentOS7のsystemdで立ち上げる時のサービスファイルの書き方

/etc/systemd/systemにalpha.serviceというファイル名で以下の内容を作成する。ファイルに実行権限は不要。
どこか間違っている、過不足等いっぱいあるかも。またアプリはalphaというUnixユーザーで実行するようにしている。
railsバージョンは4.2.2
Databaseはmysql5.6

[Unit]
Description=alpha
Wants=mysqld.service
After=mysqld.service

[Service]
User=alpha
WorkingDirectory=/home/alpha
Environment=RAILS_ENV=production
Environment=RAILS_SERVE_STATIC_FILES=1
Environment=SECRET_KEY_BASE=some_string_you_use_for_secret
SyslogIdentifier=alpha-unicorn
PIDFile=/home/alpha/tmp/pids/unicorn.pid
ExecStart=/home/alpha/.rbenv/shims/bundle exec "unicorn_rails -D -c /home/alpha/config/unicorn_config.rb -E production"

[Install]
WantedBy=multi-user.target