Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
rsync
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
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
linuxsupport
cronjobs
rsync
Merge requests
!14
Lock
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Lock
lock
into
master
Overview
0
Commits
2
Pipelines
1
Changes
2
Merged
Alex Iribarren
requested to merge
lock
into
master
4 years ago
Overview
0
Commits
2
Pipelines
1
Changes
2
Expand
0
0
Merge request reports
Compare
master
master (base)
and
latest version
latest version
8e2fdc74
2 commits,
4 years ago
2 files
+
24
−
1
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
2
Search (e.g. *.vue) (Ctrl+P)
rsync/runsync.sh
+
23
−
0
Options
#!/bin/bash
OUTPUT
=
'/alloc/output.json'
LOCKFILE
=
'/repo/.rsynclock'
log
()
{
mapfile
IN
@@ -19,6 +20,24 @@ error () {
EOF
}
# Let's make absolutely sure there's only one copy of the job running
if
[[
-f
"
$LOCKFILE
"
]]
;
then
# The lockfile exists, let's check if it's fresh
AGE
=
$((
`
date
+%s
`
-
`
stat
-c
'%Y'
$LOCKFILE
`
))
if
[[
$AGE
-gt
86400
]]
;
then
echo
"
$LOCKFILE
is over 24 hours old. It's probably stale, so get rid of it."
rm
-f
"
$LOCKFILE
"
fi
fi
# Grab the lock, exit if you fail
if
!(
set
-o
noclobber
;
echo
"
`
hostname
`
(
$$
)"
>
"
$LOCKFILE
"
)
2> /dev/null
;
then
echo
"Lock exists:
$LOCKFILE
owned by
$(
cat
$LOCKFILE
)
"
exit
fi
# Delete the lock if we die
trap
'rm -f "$LOCKFILE"; exit $?'
INT TERM EXIT
# Read the job parameters
if
[[
"
${
TOOL
}
"
==
"rsync"
]]
;
then
@@ -58,3 +77,7 @@ cat << EOF | log > $OUTPUT
"message_type": "result",
"exit_code":
${
RET
}
EOF
# Clean up after yourself, and release your trap
rm
-f
"
$LOCKFILE
"
trap
- INT TERM EXIT
Loading