-
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
570fecd
commit 61551a5
Showing
12 changed files
with
146 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
build/COPY_ROOT/etc/supervisor/supervisord/conf.d/storagemonitor.conf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
[program:storagemonitor] | ||
command=supervisor-storagemonitor.sh | ||
process_name=%(program_name)s | ||
numprocs=1 | ||
directory=/root | ||
priority=1000 | ||
autostart=true | ||
startsecs=5 | ||
startretries=3 | ||
autorestart=unexpected | ||
stopsignal=TERM | ||
stopwaitsecs=10 | ||
stopasgroup=true | ||
killasgroup=true | ||
stdout_logfile=/var/log/supervisor/storagemonitor.log | ||
stdout_logfile_maxbytes=10MB | ||
stdout_logfile_backups=1 | ||
redirect_stderr=true | ||
environment=PROC_NAME="%(program_name)s" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,7 @@ $APT_INSTALL \ | |
git \ | ||
git-lfs \ | ||
gpg \ | ||
inotify-tools \ | ||
jq \ | ||
less \ | ||
libcap2-bin \ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
build/COPY_ROOT/opt/ai-dock/bin/supervisor-storagemonitor.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#!/bin/bash | ||
|
||
trap cleanup EXIT | ||
|
||
function cleanup() { | ||
kill $(jobs -p) > /dev/null 2>&1 | ||
} | ||
|
||
function start() { | ||
printf "Starting storage monitor..\n" | ||
exec /opt/ai-dock/storage_monitor/bin/storage-monitor.sh | ||
} | ||
|
||
start 2>&1 |
35 changes: 35 additions & 0 deletions
35
build/COPY_ROOT/opt/ai-dock/storage_monitor/bin/manage-symlinks.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#!/bin/bash | ||
|
||
storage_dir="$1" | ||
stored_file="$2" | ||
event_type="$3" | ||
|
||
absolute_stored_file=$(realpath "$stored_file") | ||
subfolder=$(realpath --relative-to="$storage_dir" "$(dirname "$stored_file")") | ||
|
||
# Simplify per-image settings by keeping mappings separate | ||
source /opt/ai-dock/storage_monitor/etc/mappings.sh | ||
|
||
# Function to create symlinks for a given file and repository directory | ||
manage_symlinks() { | ||
for app_directory in "${!storage_map[@]}"; do | ||
if [[ "$subfolder" == "$app_directory" ]]; then | ||
read -ra target_dirs <<< "${storage_map["$app_directory"]}" | ||
for target_directory in "${target_dirs[@]}"; do | ||
symlink_target="$target_directory/$(basename "$stored_file")" | ||
symlink_target_dir="$(dirname "$symlink_target")" | ||
if [[ -e "$stored_file" ]]; then | ||
# Create symlinks for existing or newly created files | ||
mkdir -p "$symlink_target_dir" | ||
ln -sf "$absolute_stored_file" "$symlink_target" | ||
else | ||
# Remove symlink for deleted files | ||
rm -f "$symlink_target" | ||
fi | ||
done | ||
fi | ||
done | ||
} | ||
|
||
# Call the function to create or remove symlinks for the stored file | ||
manage_symlinks |
42 changes: 42 additions & 0 deletions
42
build/COPY_ROOT/opt/ai-dock/storage_monitor/bin/storage-monitor.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#!/bin/bash | ||
|
||
storage_dir="${WORKSPACE}storage" | ||
image_storage_dir="/opt/storage" | ||
source /opt/ai-dock/storage_monitor/etc/mappings.sh | ||
|
||
# Link files bundled in the image to $storage_dir | ||
if [[ -d $image_storage_dir ]]; then | ||
IFS=$'\n' | ||
for filepath in $(find "$image_storage_dir" -type f -name "[!.]*" ); do | ||
file_name=$(basename "$filepath") | ||
dir_name=$(dirname "$filepath") | ||
ws_file_path=${storage_dir}/$(realpath --relative-to="$image_storage_dir" "$filepath") | ||
ws_dir_name=$(dirname "$ws_file_path") | ||
|
||
mkdir -p "$ws_dir_name" | ||
ln -sf "$filepath" "$ws_file_path" | ||
done | ||
fi | ||
|
||
# Initial pass for existing files | ||
find "$storage_dir" -exec bash /opt/ai-dock/storage_monitor/bin/manage-symlinks.sh "$storage_dir" {} \; | ||
|
||
# Delete any broken symlinks caused by containers sharing a volume | ||
for app_directory in "${!storage_map[@]}"; do | ||
read -ra target_dirs <<< "${storage_map["$app_directory"]}" | ||
for target_directory in "${target_dirs[@]}"; do | ||
if [[ -e $target_directory ]]; then | ||
find "$target_directory" -xtype l -delete | ||
fi | ||
done | ||
done | ||
|
||
# Inotify loop for future changes in $storage_dir | ||
inotifywait -m -r -e create -e delete -e move --format '%e %w%f' "$storage_dir" | | ||
while read -r changed_item | ||
do | ||
event_type=$(echo "$changed_item" | awk '{print $1}') | ||
stored_file=$(echo "$changed_item" | awk '{print $2}') | ||
# Call the function to create or remove symlinks for the changed item | ||
bash /opt/ai-dock/storage_monitor/bin/manage-symlinks.sh "$storage_dir" "$stored_file" "$event_type" | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Key is relative to $WORKSPACE/storage/ | ||
|
||
declare -A storage_map | ||
#storage_map["my/models"]="/opt/app_1/models /opt/app_2/models" | ||
#storage_map["my/datasets"]="/opt/app_1/datasets /opt/app_2/datasets" | ||
|
||
# Add more mappings for other repository directories as needed |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Any files present in the container image at /opt/storage will be symlinked | ||
to $WORKSPACE/storage at startup. | ||
|
||
Files in $WORKSPACE/storage will then be linked/unlinked as defined in | ||
/opt/storage_monitor/etc/mappings.sh as they are added/moved/removed. | ||
|
||
This is where you should add models and datasets if you would like to bundle them. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters