-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Expand file tree
/
Copy pathdocker_startup.sh
More file actions
executable file
·64 lines (60 loc) · 2.4 KB
/
docker_startup.sh
File metadata and controls
executable file
·64 lines (60 loc) · 2.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/bin/bash
#============================== [License Information] ===============================
#
# This file is licensed under the terms of the GNU General Public
# License version 2. This program is licensed "as is" without any
# warranty of any kind, whether express or implied.
#
# This file is a part of the Rebuild Armbian
# https://github.com/ophub/amlogic-s9xxx-armbian
#
# Description: Custom startup script for Armbian Docker container.
# Copyright (C) 2021- https://github.com/ophub/amlogic-s9xxx-armbian
#
#======================== [Container Initialization Section] ========================
#
# Try to start Nginx service in the background if it exists.
start_nginx_service() {
echo "[SETUP] Checking and starting Nginx service..."
if ! command -v nginx >/dev/null 2>&1; then
echo "[INFO] Nginx not found, skipping."
return
fi
# Test Nginx configuration before trying to start it.
if nginx -t; then
echo "[INFO] Nginx configuration test passed."
# Start Nginx in the background.
nginx || echo "[WARNING] Failed to start Nginx daemon, but script will continue."
else
# If the configuration is bad, report it clearly and do not start.
echo "[ERROR] Nginx configuration test failed! Nginx will not be started."
fi
}
# Placeholder for other tasks.
other_initialization() {
echo "[SETUP] Performing other initialization tasks..."
# Add any other necessary commands here, for example:
# cp -rf /path/to/website_code /var/www/html/myblog
}
echo "[INIT] Container initialization started..."
# Start Nginx services.
start_nginx_service
# Perform other setup tasks.
other_initialization
#======================== [Start the Main Foreground Process] ========================
#
# This command keeps the container alive. Its lifecycle is the container's lifecycle.
# We choose sshd as the primary foreground process.
echo "[INIT] Initialization complete. Starting main process..."
if command -v sshd >/dev/null 2>&1; then
echo "[RUN] Starting SSHD as the main process..."
# Ensure the sshd run directory exists.
mkdir -p /var/run/sshd
# Use 'exec' to replace this script with the sshd process.
exec /usr/sbin/sshd -D
else
# Fallback if sshd is somehow not installed.
echo "[RUN] FATAL: sshd command not found."
echo "[RUN] Starting 'tail -f /dev/null' to keep the container alive for debugging."
exec tail -f /dev/null
fi