Skip to content

Commit

Permalink
Add systemd unicorn service
Browse files Browse the repository at this point in the history
Also create directories for new installs.

Closes #7
  • Loading branch information
jstoja authored and pushcx committed May 2, 2018
1 parent 5f0e54c commit 69767bf
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 7 deletions.
13 changes: 7 additions & 6 deletions prod.yml
Expand Up @@ -13,6 +13,13 @@
# roles:
# - { role: dns }

- name: unicorn
tags: unicorn
become: yes
hosts: www-worker
roles:
- { role: unicorn }

- name: lobsters
tags: lobsters
become: yes
Expand Down Expand Up @@ -62,9 +69,3 @@
roles:
- { role: tarsnap }

- name: unicorn
tags: unicorn
become: yes
hosts: www-worker
roles:
- { role: unicorn }
4 changes: 3 additions & 1 deletion roles/lobsters/tasks/main.yml
Expand Up @@ -92,7 +92,9 @@

- name: restart unicorn
when: clone.changed or bundler.changed or sitefiles.changed
command: pkill -USR2 -f 'unicorn_rails master'
systemd: >
name="lobsters-unicorn"
state=reloaded
- name: cp cron script
copy: >
Expand Down
28 changes: 28 additions & 0 deletions roles/unicorn/files/lobsters-unicorn.service
@@ -0,0 +1,28 @@
# Unicorn unit file for:
# Lobste.rs -- https://lobste.rs

[Unit]
Description=Lobsters Unicorn Server
#Wants=mariadb.service
#After=mariadb.service

[Service]
User=lobsters
Group=lobsters
WorkingDirectory=/srv/lobste.rs/http/
Environment=RAILS_ENV=production
SyslogIdentifier=lobsters-unicorn
PIDFile=/srv/lobste.rs/run/unicorn.pid

Restart=always
RestartSec=60
StartLimitBurst=5
StartLimitInterval=3600

ExecStart=/usr/local/bin/bundle exec "unicorn_rails -c config/unicorn.conf.rb -E production -D config.ru"
ExecReload=/usr/bin/kill -USR2 $MAINPID
ExecStop=/usr/bin/kill -QUIT $MAINPID

[Install]
WantedBy=multi-user.target

23 changes: 23 additions & 0 deletions roles/unicorn/tasks/main.yml
Expand Up @@ -3,10 +3,33 @@
- include_tasks: yum.yml
when: "'{{ family }}' == 'redhat'"

- name: lobsters directory
file: >
path="/srv/lobste.rs/{{ item }}/"
state=directory
with_items:
- http
- run
- log

- name: copy up unicorn config
copy: >
src="unicorn.conf.rb"
dest="/srv/lobste.rs/http/config"
owner=lobsters
group=lobsters
mode="0644"
- name: copy unicorn systemd service config
copy: >
src="lobsters-unicorn.service"
dest="/etc/systemd/system/"
owner=lobsters
group=lobsters
mode="0440"
- name: just force systemd to reread configs
systemd: >
name="lobsters-unicorn"
enabled=yes
daemon_reload=yes

0 comments on commit 69767bf

Please sign in to comment.