veltrixcode commited on
Commit
46e92bc
·
verified ·
1 Parent(s): 2e42fd7

Update start.sh

Browse files
Files changed (1) hide show
  1. start.sh +50 -20
start.sh CHANGED
@@ -1,23 +1,53 @@
1
  #!/bin/bash
2
 
3
- # 1. Setup MySQL Directories (Non-Persistent Mode)
4
- # Ensure the socket directory exists and is owned by mysql
5
- mkdir -p /var/run/mysqld
6
- chown -R mysql:mysql /var/run/mysqld
7
-
8
- # Ensure the data directory permissions are correct
9
- chown -R mysql:mysql /var/lib/mysql
10
-
11
- # 2. Start MySQL
12
- # We use 'runuser' to start it as the 'mysql' user to avoid "running as root" errors
13
- # We also skip networking checks to ensure it binds locally quickly
14
- echo "Starting MySQL..."
15
- runuser -u mysql -- /usr/bin/mysqld_safe --skip-grant-tables &
16
-
17
- # Wait a few seconds for MySQL to initialize
18
- sleep 5
19
-
20
- # 3. Start code-server
21
- echo "Starting code-server..."
22
- # Run as 'coder' user
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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