Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
s6-base
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Monitor
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ai3
docker
s6-base
Commits
1fa311b2
Commit
1fa311b2
authored
3 years ago
by
ale
Browse files
Options
Downloads
Patches
Plain Diff
Add a simple cron job wrapper script
parent
a1fc2397
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
Dockerfile
+1
-0
1 addition, 0 deletions
Dockerfile
README.md
+6
-17
6 additions, 17 deletions
README.md
every
+21
-0
21 additions, 0 deletions
every
with
28 additions
and
17 deletions
Dockerfile
+
1
−
0
View file @
1fa311b2
...
@@ -6,6 +6,7 @@ ENV S6_READ_ONLY_ROOT=1 \
...
@@ -6,6 +6,7 @@ ENV S6_READ_ONLY_ROOT=1 \
COPY
etc/ /etc/
COPY
etc/ /etc/
COPY
deb_autistici_org.gpg /usr/share/keyrings/deb.autistici.org.gpg
COPY
deb_autistici_org.gpg /usr/share/keyrings/deb.autistici.org.gpg
COPY
every /usr/bin/every
ADD
https://github.com/just-containers/s6-overlay/releases/download/v2.2.0.3/s6-overlay-amd64.tar.gz /tmp/
ADD
https://github.com/just-containers/s6-overlay/releases/download/v2.2.0.3/s6-overlay-amd64.tar.gz /tmp/
...
...
This diff is collapsed.
Click to expand it.
README.md
+
6
−
17
View file @
1fa311b2
...
@@ -55,7 +55,7 @@ it is simpler to create a secondary service that will run a loop with
...
@@ -55,7 +55,7 @@ it is simpler to create a secondary service that will run a loop with
*sleep*
:
*sleep*
:
```
```
#!/bin/sh
-e
#!/bin/sh
period
=
600
period
=
600
...
@@ -65,27 +65,16 @@ while true; do
...
@@ -65,27 +65,16 @@ while true; do
done
done
```
```
while the above is ok for short periods, for longer ones (and for more
To simplify this problem, we ship a simple shell-based "cron job
r
esource-intensive jobs) it might be better to wait a random amount of
r
unner" that implements a sligthly more sophisticated version of the
time at startup. Consider that "dash" (/bin/sh in Debian) has no
above loop (with random initial delay to stagger jobs on restart)
$RANDOM, so something like this might be necessary
:
called
*every*
. The above example should then be written like this
:
```
```
#!/bin/sh
#!/bin/sh
exec
every 600 /usr/bin/my-command foo bar
period
=
${
SCAN_PERIOD_SECS
:-
86400
}
offset
=
$(
shuf
-i
0-
${
period
}
-n
1
)
sleep
$offset
while
true
;
do
/usr/bin/my-command foo bar
sleep
$period
done
```
```
Randomization maximizes the chances that the job will run regularly
even in face of restarts etc.
## Differences with stock *s6-overlay*
## Differences with stock *s6-overlay*
The base s6-overlay distribution is modified slightly to work around
The base s6-overlay distribution is modified slightly to work around
...
...
This diff is collapsed.
Click to expand it.
every
0 → 100755
+
21
−
0
View file @
1fa311b2
#!/bin/sh
#
# Cron runner for a single job.
#
if
[
$#
-lt
2
]
;
then
echo
"Usage:
$0
<period> <cmd>..."
>
&2
exit
2
fi
period
=
"
$1
"
shift
# Work around the lack of $RANDOM in dash.
offset
=
$(
shuf
-i
0-
${
period
}
-n
1
)
sleep
${
offset
}
while
true
;
do
"
$@
"
sleep
${
period
}
done
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment