Skip to content

Commit

Permalink
Centralize logging
Browse files Browse the repository at this point in the history
Replace cron job with systemd timer so that all relevant events are
logged in the same format and rotated accordingly.
  • Loading branch information
jugglinmike committed Oct 20, 2018
1 parent 40d50f6 commit 29f875e
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 20 deletions.
9 changes: 4 additions & 5 deletions files/wpt-pull-and-restart.sh → files/sync-wpt.sh
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
#!/usr/bin/env bash
set -e

cd /root/web-platform-tests/

function parse_git_hash() {
git rev-parse --short HEAD 2> /dev/null
}

GIT_HEAD=$(parse_git_hash)

git pull origin master
git pull --quiet origin master

GIT_NEW_HEAD=$(parse_git_hash)


if [ "$GIT_HEAD" != "$GIT_NEW_HEAD" ]
then
echo "web-platform-tests HEAD is now ${GIT_NEW_HEAD} restarting wpt service"
echo "HEAD changed (${GIT_HEAD} -> ${GIT_NEW_HEAD}). Restarting service."
systemctl restart wpt
else
echo "HEAD unchanged (${GIT_HEAD}). Taking no action."
fi

11 changes: 11 additions & 0 deletions files/wpt-sync.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[Unit]
Description=Web Platform Test Synchronization Service
After=network.target auditd.service wpt.service

[Service]
WorkingDirectory=/root/web-platform-tests/
ExecStart=/root/sync-wpt.sh
KillMode=control-group

[Install]
WantedBy=multi-user.target
9 changes: 9 additions & 0 deletions files/wpt-sync.timer
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[Unit]
Description=Synchronize WPT every 60 seconds

[Timer]
OnBootSec=0 seconds
OnUnitActiveSec=1 minute

[Install]
WantedBy=timers.target
30 changes: 15 additions & 15 deletions playbook.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,18 @@
name: virtualenv
virtualenv: ~/web-platform-tests/_venv

- name: ensure wpt service is configured
template:
src: files/wpt.service
- name: Install WPT services
copy:
src: '{{item}}'
dest: /etc/systemd/system/
with_items:
- files/wpt.service
- files/wpt-sync.service
- files/wpt-sync.timer

- name: ensure conditional restart script is in the correct location
template:
src: files/wpt-pull-and-restart.sh
- name: Install WPT synchronization script
copy:
src: files/sync-wpt.sh
dest: /root/
owner: root
mode: '0700'
Expand All @@ -55,22 +59,18 @@
src: files/config-{{ vagrant_provision | ternary("development", "production") }}.json
dest: /root/web-platform-tests/config.json

- name: Enable the wpt service in systemd
- name: Enable WPT services in systemd
systemd:
enabled: True
name: wpt
name: '{{item}}'
state: started
with_items:
- wpt
- wpt-sync

- include: certbot.yml
when: not vagrant_provision

- name: Add cron job to sync wpt
cron:
name: Synchronize WPT
job: "/root/wpt-pull-and-restart.sh"
minute: "*"


# force_restart is false by default this can be set via the command line using --extra-vars
# $ ansible-playbook playbook.yml --extra-vars "force_restart=true"
- name: reboot the machine
Expand Down

0 comments on commit 29f875e

Please sign in to comment.