Merge lp:~hloeung/ubuntu-repository-cache/splay-cron-daily into lp:ubuntu-repository-cache

Proposed by Haw Loeung
Status: Merged
Approved by: Colin Misare
Approved revision: 331
Merged at revision: 331
Proposed branch: lp:~hloeung/ubuntu-repository-cache/splay-cron-daily
Merge into: lp:ubuntu-repository-cache
Diff against target: 48 lines (+28/-0)
2 files modified
files/cron_random_sleep.sh (+23/-0)
reactive/ubuntu_repository_cache.py (+5/-0)
To merge this branch: bzr merge lp:~hloeung/ubuntu-repository-cache/splay-cron-daily
Reviewer Review Type Date Requested Status
Colin Misare Approve
Canonical IS Reviewers Pending
Review via email: mp+399553@code.launchpad.net

Commit message

Ensure daily apache2 graceful restart is splayed - LP:1918211

We ship out a random sleep script to cron.daily to ensure that
graceful restarts from logrotation is spread out across the various
units.

To post a comment you must log in.
Revision history for this message
Canonical IS Mergebot (canonical-is-mergebot) wrote :

This merge proposal is being monitored by mergebot. Change the status to Approved to merge.

Revision history for this message
Colin Misare (cmisare) wrote :

LGTM

review: Approve
Revision history for this message
Canonical IS Mergebot (canonical-is-mergebot) wrote :

Change successfully merged at revision 331

Revision history for this message
Junien Fridrick (axino) wrote :

May I suggest RAND=$(( RANDOM % (MAX-MIN) + MIN )) ?

Revision history for this message
Haw Loeung (hloeung) wrote :

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file 'files/cron_random_sleep.sh'
2--- files/cron_random_sleep.sh 1970-01-01 00:00:00 +0000
3+++ files/cron_random_sleep.sh 2021-03-11 23:44:25 +0000
4@@ -0,0 +1,23 @@
5+#!/bin/bash
6+
7+# Taken from basenode.
8+
9+# Maximum of 20 mins.
10+MAX=1200
11+# Minimum of 30 secs.
12+MIN=30
13+
14+RAND=$RANDOM
15+(( RAND %= $MAX ))
16+
17+if [ $RAND -lt $MIN ]; then
18+ echo $RAND
19+ (( RAND += MIN ))
20+fi
21+
22+# if we're running it from the command line, don't sleep
23+if [ -t 0 ]; then
24+ echo skipped sleep $RAND
25+else
26+ sleep $RAND
27+fi
28
29=== modified file 'reactive/ubuntu_repository_cache.py'
30--- reactive/ubuntu_repository_cache.py 2021-03-08 22:18:19 +0000
31+++ reactive/ubuntu_repository_cache.py 2021-03-11 23:44:25 +0000
32@@ -6,6 +6,7 @@
33
34 import os
35 import pwd
36+import shutil
37
38 from charms import reactive
39 from charms.layer import status
40@@ -68,6 +69,10 @@
41 LOG('Disabling {}'.format(azure_disk_warning))
42 host.service_pause(azure_disk_warning)
43
44+ # We want to ensure not all units rotate out and graceful
45+ # restart/reload apache at the same time.
46+ shutil.copy2('files/cron_random_sleep.sh', '/etc/cron.daily/000-cron-random-sleep')
47+
48 reactive.set_flag('ubuntu-repository-cache.configured')
49
50

Subscribers

People subscribed via source and target branches