Skip to content

Use systemd timer instead of crontab #92

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,13 @@ cd ../rurema-search
cap vagrant deploy
cd ../docs.ruby-lang.org
vagrant ssh
sudo systemctl restart nginx
sudo su - rurema
crontab -l
sudo systemctl start rdoc-static-all.service bc-setup-all.service &
sudo systemctl status rdoc-static-all.service bc-setup-all.service bc-static-all.service update-rurema-index.service
```

- Run commands in crontab as rurema user (ignore error of `system/fastly-purge-key`)
- Open `https://localhost:10443/` in browser (ignore certificate error (`NET::ERR_CERT_AUTHORITY_INVALID`) because of using self signed certificate generated by `provision/selfsigned.yml`)
- Run `sudo systemctl start rdoc-static-all.service` to update English documents.
- Run `sudo systemctl start bc-setup-all.service` to update Japanese documents.
- Run `sudo systemctl status rdoc-static-all.service bc-setup-all.service bc-static-all.service update-rurema-index.service` to see progress.
- `Active: activating (start) since ...` means running.
- `Active: inactive (dead) since ...` means finished.
55 changes: 34 additions & 21 deletions provision/playbook.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,27 +78,36 @@
- '/var/rubydoc'
- '/var/rubydoc/rurema-search/shared'

- name: 'Cron: rdoc'
cron:
name: 'rdoc'
minute: '20'
hour: '13'
job: 'cd /var/www/docs.ruby-lang.org/current; ruby system/rdoc-static-all'
user: 'rurema'
- name: 'Cron: bitclust'
cron:
name: 'bitclust'
minute: '15'
hour: '0'
job: 'cd /var/www/docs.ruby-lang.org/current; ruby system/bc-setup-all; ruby system/bc-static-all'
user: 'rurema'
- name: 'Cron: update-rurema-index'
cron:
name: 'update-rurema-index'
minute: '15'
hour: '2'
job: 'cd /var/www/docs.ruby-lang.org/current; system/update-rurema-index'
user: 'rurema'
- name: 'Copy systemd unit files'
copy:
dest: '/etc/systemd/system/{{ item }}'
src: 'systemd/{{ item }}'
with_items:
- 'update-docs-en.timer'
- 'rdoc-static-all.service'
- 'update-docs-ja.timer'
- 'bc-setup-all.service'
- 'bc-static-all.path'
- 'bc-static-all.service'
- 'update-rurema-index.path'
- 'update-rurema-index.service'
- name: 'Enable systemd units'
systemd:
name: '{{ item }}'
state: started
enabled: yes
with_items:
- 'update-docs-en.timer'
- 'update-docs-ja.timer'
- 'bc-static-all.path'
- 'update-rurema-index.path'

- name: 'Copy tmpfiles.d/docs.ruby-lang.org.conf'
copy:
dest: '/etc/tmpfiles.d/docs.ruby-lang.org.conf'
content: |
d /run/docs.ruby-lang.org 0755 rurema rurema
notify: 'systemd-tmpfiles'

- name: 'git clone rurema/doctree'
git:
Expand Down Expand Up @@ -145,3 +154,7 @@
file:
dest: '/etc/nginx/sites-enabled/default'
state: absent

handlers:
- name: 'systemd-tmpfiles'
command: '/bin/systemd-tmpfiles --create --remove'
5 changes: 5 additions & 0 deletions provision/selfsigned.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,8 @@
remote_src: yes
src: '/etc/letsencrypt/live/docs-origin.ruby-lang.org/fullchain.pem'
dest: '/etc/letsencrypt/live/docs-origin.ruby-lang.org/chain.pem'

- name: 'Restart nginx'
systemd:
state: restarted
name: 'nginx.service'
11 changes: 11 additions & 0 deletions provision/systemd/bc-setup-all.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[Unit]
Description=Run bc-setup-all

[Service]
Type=oneshot
WorkingDirectory=/var/www/docs.ruby-lang.org/current
ExecStart=/usr/bin/ruby system/bc-setup-all
User=rurema
Group=rurema
#ExecStartPre=!/usr/bin/install -o rurema -g rurema -d /run/docs.ruby-lang.org
ExecStartPost=/usr/bin/touch /run/docs.ruby-lang.org/bc-setup-all.updated
8 changes: 8 additions & 0 deletions provision/systemd/bc-static-all.path
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[Unit]
Description=Trigger bc-static-all

[Path]
PathModified=/run/docs.ruby-lang.org/bc-setup-all.updated

[Install]
WantedBy=multi-user.target
11 changes: 11 additions & 0 deletions provision/systemd/bc-static-all.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[Unit]
Description=Run bc-static-all

[Service]
Type=oneshot
WorkingDirectory=/var/www/docs.ruby-lang.org/current
ExecStart=/usr/bin/ruby system/bc-static-all
User=rurema
Group=rurema
#ExecStartPre=!/usr/bin/install -o rurema -g rurema -d /run/docs.ruby-lang.org
ExecStartPost=/usr/bin/touch /run/docs.ruby-lang.org/bc-static-all.updated
11 changes: 11 additions & 0 deletions provision/systemd/rdoc-static-all.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[Unit]
Description=Run rdoc-static-all

[Service]
Type=oneshot
WorkingDirectory=/var/www/docs.ruby-lang.org/current
ExecStart=/usr/bin/ruby system/rdoc-static-all
User=rurema
Group=rurema
#ExecStartPre=!/usr/bin/install -o rurema -g rurema -d /run/docs.ruby-lang.org
ExecStartPost=/usr/bin/touch /run/docs.ruby-lang.org/rdoc-static-all.updated
10 changes: 10 additions & 0 deletions provision/systemd/update-docs-en.timer
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[Unit]
Description=Update docs.ruby-lang.org/en/

[Timer]
OnCalendar=*-*-* 13:20
Persistent=true
Unit=rdoc-static-all.service

[Install]
WantedBy=timers.target
10 changes: 10 additions & 0 deletions provision/systemd/update-docs-ja.timer
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[Unit]
Description=Update docs.ruby-lang.org/ja/

[Timer]
OnCalendar=*-*-* 0:15
Persistent=true
Unit=bc-setup-all.service

[Install]
WantedBy=timers.target
8 changes: 8 additions & 0 deletions provision/systemd/update-rurema-index.path
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[Unit]
Description=Trigger update-rurema-index

[Path]
PathModified=/run/docs.ruby-lang.org/bc-static-all.updated

[Install]
WantedBy=multi-user.target
11 changes: 11 additions & 0 deletions provision/systemd/update-rurema-index.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[Unit]
Description=Update docs.ruby-lang.org/ja/search/

[Service]
Type=oneshot
WorkingDirectory=/var/www/docs.ruby-lang.org/current
ExecStart=/bin/bash system/update-rurema-index
User=rurema
Group=rurema
#ExecStartPre=!/usr/bin/install -o rurema -g rurema -d /run/docs.ruby-lang.org
ExecStartPost=/usr/bin/touch /run/docs.ruby-lang.org/update-rurema-index.updated