Merge "Do not race with locks for the sync/wrapper script"
This commit is contained in:
commit
45ab41ad54
|
@ -32,12 +32,15 @@ function start_service {
|
||||||
$CONTAINER_CMD $@
|
$CONTAINER_CMD $@
|
||||||
}
|
}
|
||||||
|
|
||||||
|
jobs_file="{{ tripleo_systemd_wrapper_service_dir }}/{{ tripleo_systemd_wrapper_service_name }}/processes"
|
||||||
|
[ -s "$jobs_file" ] || exit 0 # nothing to do, no need for locking, just exit
|
||||||
|
|
||||||
exec {lock_fd}>/var/lock/{{ tripleo_systemd_wrapper_service_name }}-processes.lock || exit 1
|
exec {lock_fd}>/var/lock/{{ tripleo_systemd_wrapper_service_name }}-processes.lock || exit 1
|
||||||
# In case service_wrapper script already locked the commands, we just wait.
|
# In case service_wrapper script already locked the commands, we just wait for a 10 sec.
|
||||||
flock "$lock_fd"
|
flock -w 10 "$lock_fd" || exit 1
|
||||||
|
|
||||||
IFS=$'\n'
|
IFS=$'\n'
|
||||||
for LINE in $(cat {{ tripleo_systemd_wrapper_service_dir }}/{{ tripleo_systemd_wrapper_service_name }}/processes); do
|
for LINE in $(cat ${jobs_file}); do
|
||||||
NETNS=$(echo $LINE | awk '{ print $1 }')
|
NETNS=$(echo $LINE | awk '{ print $1 }')
|
||||||
IFS=$' ' ARGS=$(echo $LINE | sed -e "s|$NETNS ||" | xargs)
|
IFS=$' ' ARGS=$(echo $LINE | sed -e "s|$NETNS ||" | xargs)
|
||||||
# TODO(emilien) investigate if we should rather run docker/podman ps instead of ps on the host
|
# TODO(emilien) investigate if we should rather run docker/podman ps instead of ps on the host
|
||||||
|
@ -46,6 +49,6 @@ for LINE in $(cat {{ tripleo_systemd_wrapper_service_dir }}/{{ tripleo_systemd_w
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
# truncate the file so we don't start them again
|
# truncate the file so we don't start them again
|
||||||
:> {{ tripleo_systemd_wrapper_service_dir }}/{{ tripleo_systemd_wrapper_service_name }}/processes
|
:> "$jobs_file"
|
||||||
|
|
||||||
flock -u "$lock_fd"
|
flock -u "$lock_fd"
|
||||||
|
|
|
@ -7,11 +7,10 @@ ARGS="$@"
|
||||||
NETNS=$(ip netns identify)
|
NETNS=$(ip netns identify)
|
||||||
|
|
||||||
exec {lock_fd}>/var/lock/{{ tripleo_systemd_wrapper_service_name }}-processes.lock || exit 1
|
exec {lock_fd}>/var/lock/{{ tripleo_systemd_wrapper_service_name }}-processes.lock || exit 1
|
||||||
# In case service_sync script already locked the commands, we just wait.
|
# In case service_sync script already locked the commands, we just wait for a 10 sec.
|
||||||
flock "$lock_fd"
|
flock -w 10 "$lock_fd" || exit 1
|
||||||
|
|
||||||
echo "$NETNS $ARGS" >> {{ tripleo_systemd_wrapper_service_dir }}/{{ tripleo_systemd_wrapper_service_name }}/processes
|
echo "$NETNS $ARGS" >> {{ tripleo_systemd_wrapper_service_dir }}/{{ tripleo_systemd_wrapper_service_name }}/processes
|
||||||
# only update the timestamp which fires systemd if there was an update
|
# only update the timestamp which fires systemd if there was an update
|
||||||
|
flock -u "$lock_fd" # prevents locking the processes file, while updating
|
||||||
date > {{ tripleo_systemd_wrapper_service_dir }}/{{ tripleo_systemd_wrapper_service_name }}/processes-timestamp
|
date > {{ tripleo_systemd_wrapper_service_dir }}/{{ tripleo_systemd_wrapper_service_name }}/processes-timestamp
|
||||||
|
|
||||||
flock -u "$lock_fd"
|
|
||||||
|
|
Loading…
Reference in New Issue