Skip to content

Commit 45c1787

Browse files
committed
Added functionality to run custom scripts on startup
1 parent d82ce16 commit 45c1787

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

src/bash_functions.sh

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,3 +258,49 @@ fix_capabilities() {
258258
fi
259259
echo ""
260260
}
261+
262+
# New function to run custom initialization scripts
263+
run_custom_init_scripts() {
264+
local custom_init_dir="/custom-cont-init.d"
265+
266+
# Check if the directory exists
267+
if [ ! -d "$custom_init_dir" ]; then
268+
echo " [i] Custom init directory $custom_init_dir does not exist, skipping"
269+
return 0
270+
fi
271+
272+
echo " [i] Checking for custom initialization scripts in $custom_init_dir"
273+
274+
# Find all executable scripts or make them executable
275+
find "$custom_init_dir" -type f | sort | while read -r script; do
276+
# Check if file is already executable
277+
if [ ! -x "$script" ]; then
278+
echo " [i] Making $script executable"
279+
chmod +x "$script" 2>/dev/null || {
280+
echo " [!] Failed to make $script executable, skipping"
281+
continue
282+
}
283+
fi
284+
285+
# Extract the filename
286+
filename=$(basename "$script")
287+
288+
# Check if the filename starts with a number
289+
if [[ "$filename" =~ ^[0-9]+ ]]; then
290+
echo " [i] Running custom init script: $script"
291+
# Run the script in background with output redirected to docker logs
292+
# Use 'exec' to run in a subshell and avoid blocking
293+
sleep 10
294+
(exec "$script" 2>&1 | sed "s/^/[Custom Init: $filename] /") &
295+
296+
# Store the PID in case we want to track it later
297+
local script_pid=$!
298+
echo " [i] Started $script with PID $script_pid"
299+
else
300+
echo " [i] Skipping $script, filename doesn't start with a number"
301+
fi
302+
done
303+
304+
echo " [i] Finished processing custom initialization scripts"
305+
return 0
306+
}

src/start.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ start() {
4545
# Install the logrotate config file
4646
install_logrotate
4747

48+
# Run custom initialization scripts (new addition)
49+
run_custom_init_scripts || echo " [!] Error running custom init scripts, continuing with startup"
50+
4851
#migrate Gravity Database if needed:
4952
migrate_gravity
5053

0 commit comments

Comments
 (0)