Skip to content

Commit

Permalink
Docker: Don't increase number of inotfiy watches
Browse files Browse the repository at this point in the history
  • Loading branch information
frzb committed Sep 23, 2018
1 parent f93847d commit 702a382
Showing 1 changed file with 49 additions and 46 deletions.
95 changes: 49 additions & 46 deletions scripts/create_plugin
Original file line number Diff line number Diff line change
Expand Up @@ -23,62 +23,65 @@ OUTFILE_FINAL=/tmp/plugin_file_list_final
DPKG_STATUS=/var/lib/dpkg/status
INITIAL_DPKG_STATUS=/tmp/initial_status
FINAL_DPKG_STATUS=/tmp/dpkg_status
PID_FILE=/tmp/plugin_create_pid

function start {
echo "200000" | sudo tee /proc/sys/fs/inotify/max_user_watches

sudo rm -fv $OUTFILE
rm -fv $OUTFILE_FINAL

# TODO Also track deleted files
# According to strace is looks like --exclude is not preventing building the
# "watches" for the excluded directories but filters all file system events on them.
if [ $(which inotifywait) ]; then
sudo rm -f $OUTFILE
nohup sudo inotifywait -m -r --format '%w%f' -e create -e attrib -e moved_from -e moved_to -e modify --exclude $EXCLUDE -o $OUTFILE / > /tmp/plugin.log 2>&1 &
else
echo 'inotifywait is missing.'
echo 'Please install the package inotify-tools'
exit
fi

PID=$!

echo "PID of the process watch for file changes is: $PID"

echo $PID > /tmp/plugin_create_pid

# Inotifywait takes some time to build up the recursive file watching on
# / - so we have to wait and verify that we only proceed after the prepations
# are done.
while ! grep -q 'Watches established.' /tmp/plugin.log; do
echo -ne 'Waiting for file watching to be established...\r'
sleep 0.2
done

cp $DPKG_STATUS $INITIAL_DPKG_STATUS
# Inside a Docker container '/proc' is read-only, so we are skipping this step.
if ! grep -q docker /proc/1/cgroup; then
echo "200000" | sudo tee /proc/sys/fs/inotify/max_user_watches
fi

sudo rm -fv $OUTFILE $OUTFILE_FINAL $INITIAL_DPKG_STATUS $FINAL_DPKG_STATUS $PID_FILE

# TODO Also track deleted files
# According to strace is looks like --exclude is not preventing building the
# "watches" for the excluded directories but filters all file system events on them.
if [ $(which inotifywait) ]; then
sudo rm -f $OUTFILE
nohup sudo inotifywait -m -r --format '%w%f' -e create -e attrib -e moved_from -e moved_to -e modify --exclude $EXCLUDE -o $OUTFILE / > /tmp/plugin.log 2>&1 &
else
echo 'inotifywait is missing.'
echo 'Please install the package inotify-tools'
exit
fi

PID=$!

echo "PID of the process watch for file changes is: $PID"

echo $PID > $PID_FILE

# Inotifywait takes some time to build up the recursive file watching on
# / - so we have to wait and verify that we only proceed after the prepations
# are done.
while ! grep -q 'Watches established.' /tmp/plugin.log; do
echo -ne 'Waiting for file watching to be established...\r'
sleep 0.2
done

cp $DPKG_STATUS $INITIAL_DPKG_STATUS
}

function finish {
plugin_name=$1
plugin_name=$1

sudo kill $(cat /tmp/plugin_create_pid)
sudo kill $(cat /tmp/plugin_create_pid)

dpkg_status.py --old $INITIAL_DPKG_STATUS --new $DPKG_STATUS --diff > $FINAL_DPKG_STATUS
dpkg_status.py --old $INITIAL_DPKG_STATUS --new $DPKG_STATUS --diff > $FINAL_DPKG_STATUS

# Test all collected files if they really exists and if so write them
# to a final file list.
# Finally add the dpkg_status file we create beforehand.
while read path; do
if [ -f "$path" ]; then
echo $path
echo $path >> "$OUTFILE_FINAL"
fi
done < <(sort -u $OUTFILE)
# Test all collected files if they really exists and if so write them
# to a final file list.
# Finally add the dpkg_status file we create beforehand.
while read path; do
if [ -f "$path" ]; then
echo $path
echo $path >> "$OUTFILE_FINAL"
fi
done < <(sort -u $OUTFILE)

echo $FINAL_DPKG_STATUS >> $OUTFILE_FINAL
echo $FINAL_DPKG_STATUS >> $OUTFILE_FINAL

tar -czvf $plugin_name.tar.gz -P -T $OUTFILE_FINAL
tar -czvf $plugin_name.tar.gz -P -T $OUTFILE_FINAL
}

function upload {
Expand Down

0 comments on commit 702a382

Please sign in to comment.