Spaces:
Sleeping
Sleeping
Update start.sh
Browse files
start.sh
CHANGED
|
@@ -1,23 +1,53 @@
|
|
| 1 |
#!/bin/bash
|
| 2 |
|
| 3 |
-
#
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
#
|
| 21 |
-
|
| 22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
exec runuser -u coder -- code-server --bind-addr 0.0.0.0:7860 --auth none /home/coder/projects
|
|
|
|
| 1 |
#!/bin/bash
|
| 2 |
|
| 3 |
+
# Define directories
|
| 4 |
+
MYSQL_DATA_DIR="/var/lib/mysql"
|
| 5 |
+
MYSQL_RUN_DIR="/var/run/mysqld"
|
| 6 |
+
|
| 7 |
+
echo ">>> Setting up MySQL environment..."
|
| 8 |
+
|
| 9 |
+
# 1. Prepare Runtime Directory (Socket)
|
| 10 |
+
# This is critical because /var/run is often cleared on restart
|
| 11 |
+
mkdir -p "$MYSQL_RUN_DIR"
|
| 12 |
+
chown -R mysql:mysql "$MYSQL_RUN_DIR"
|
| 13 |
+
chmod 777 "$MYSQL_RUN_DIR"
|
| 14 |
+
|
| 15 |
+
# 2. Check and Initialize Data Directory
|
| 16 |
+
# If the 'mysql' database doesn't exist, we must initialize it.
|
| 17 |
+
if [ ! -d "$MYSQL_DATA_DIR/mysql" ]; then
|
| 18 |
+
echo ">>> MySQL data directory is empty. Initializing..."
|
| 19 |
+
|
| 20 |
+
# Ensure ownership before initialization
|
| 21 |
+
chown -R mysql:mysql "$MYSQL_DATA_DIR"
|
| 22 |
+
|
| 23 |
+
# Initialize insecurely (empty root password) for practice
|
| 24 |
+
mysqld --initialize-insecure --user=mysql --datadir="$MYSQL_DATA_DIR"
|
| 25 |
+
|
| 26 |
+
echo ">>> Initialization complete."
|
| 27 |
+
else
|
| 28 |
+
echo ">>> MySQL data directory appears populated."
|
| 29 |
+
fi
|
| 30 |
+
|
| 31 |
+
# Ensure ownership is correct (just in case)
|
| 32 |
+
chown -R mysql:mysql "$MYSQL_DATA_DIR"
|
| 33 |
+
|
| 34 |
+
# 3. Start MySQL in the Background
|
| 35 |
+
echo ">>> Starting MySQL Server..."
|
| 36 |
+
# We use mysqld_safe directly as user 'mysql'
|
| 37 |
+
runuser -u mysql -- /usr/bin/mysqld_safe --skip-grant-tables --skip-networking=0 &
|
| 38 |
+
|
| 39 |
+
# 4. Wait for MySQL to be ready
|
| 40 |
+
echo ">>> Waiting for MySQL to start..."
|
| 41 |
+
# Loop until we can connect or 30 seconds pass
|
| 42 |
+
for i in {1..30}; do
|
| 43 |
+
if mysqladmin ping -u root --silent; then
|
| 44 |
+
echo ">>> MySQL is up and running!"
|
| 45 |
+
break
|
| 46 |
+
fi
|
| 47 |
+
echo "Waiting for MySQL... ($i/30)"
|
| 48 |
+
sleep 1
|
| 49 |
+
done
|
| 50 |
+
|
| 51 |
+
# 5. Start code-server
|
| 52 |
+
echo ">>> Starting code-server..."
|
| 53 |
exec runuser -u coder -- code-server --bind-addr 0.0.0.0:7860 --auth none /home/coder/projects
|