samarth upadhyay commited on
Commit
782e41b
·
verified ·
1 Parent(s): d165403

Update start.sh

Browse files
Files changed (1) hide show
  1. start.sh +20 -23
start.sh CHANGED
@@ -2,43 +2,40 @@
2
 
3
  # --- 1. Configure & Start PostgreSQL ---
4
  echo "Starting PostgreSQL..."
5
-
6
- # Start the service (as user 'postgres')
7
  service postgresql start
8
 
9
- # Wait a moment for it to boot
10
- sleep 3
 
 
 
11
 
12
- # Create a generic 'playground' user and database.
13
- # We don't set a password because we will rely on local trust.
14
- su - postgres -c "psql -c \"CREATE USER playground SUPERUSER;\""
15
- su - postgres -c "psql -c \"CREATE DATABASE playground OWNER playground;\""
16
-
17
- # Edit pg_hba.conf to trust ALL local connections (removes password requirement)
18
- # This file location depends on the version installed by apt, usually /etc/postgresql/13/main/pg_hba.conf
19
- # We use a wildcard find to locate it.
20
  PG_CONF=$(find /etc/postgresql -name "pg_hba.conf")
 
 
21
  echo "host all all 127.0.0.1/32 trust" > $PG_CONF
 
 
 
22
  echo "local all all trust" >> $PG_CONF
23
 
24
- # Restart Postgres to apply "trust" settings
25
  service postgresql restart
26
 
 
 
 
 
27
 
28
  # --- 2. Configure & Start MySQL (MariaDB) ---
29
  echo "Starting MySQL..."
30
-
31
- # Start the service
32
  service mariadb start
33
 
34
- # Wait a moment
35
- sleep 3
36
-
37
- # Create the playground database and a root user that can connect from localhost without password
38
- # In MariaDB/MySQL on Debian, the unix socket authentication is default,
39
- # but for Python we often want TCP. We'll create a wide-open user.
40
- mysql -e "CREATE DATABASE playground;"
41
- mysql -e "CREATE USER 'playground'@'localhost';"
42
  mysql -e "GRANT ALL PRIVILEGES ON *.* TO 'playground'@'localhost';"
43
  mysql -e "FLUSH PRIVILEGES;"
44
 
 
2
 
3
  # --- 1. Configure & Start PostgreSQL ---
4
  echo "Starting PostgreSQL..."
 
 
5
  service postgresql start
6
 
7
+ # Wait loop for Postgres to be ready
8
+ until pg_isready -h localhost; do
9
+ echo "Waiting for Postgres..."
10
+ sleep 1
11
+ done
12
 
13
+ # Setup 'playground' user/db with no password requirement (Trust Auth)
14
+ # We overwrite pg_hba.conf to trust local connections completely
 
 
 
 
 
 
15
  PG_CONF=$(find /etc/postgresql -name "pg_hba.conf")
16
+
17
+ # Allow IPv4 localhost
18
  echo "host all all 127.0.0.1/32 trust" > $PG_CONF
19
+ # Allow IPv6 localhost (Fixes the ::1 connection error)
20
+ echo "host all all ::1/128 trust" >> $PG_CONF
21
+ # Allow Local Unix Socket
22
  echo "local all all trust" >> $PG_CONF
23
 
24
+ # Restart to apply changes
25
  service postgresql restart
26
 
27
+ # Create user/db if they don't exist
28
+ su - postgres -c "psql -c \"CREATE USER playground SUPERUSER;\""
29
+ su - postgres -c "psql -c \"CREATE DATABASE playground OWNER playground;\""
30
+
31
 
32
  # --- 2. Configure & Start MySQL (MariaDB) ---
33
  echo "Starting MySQL..."
 
 
34
  service mariadb start
35
 
36
+ # Create 'playground' user with full access
37
+ mysql -e "CREATE DATABASE IF NOT EXISTS playground;"
38
+ mysql -e "CREATE USER IF NOT EXISTS 'playground'@'localhost';"
 
 
 
 
 
39
  mysql -e "GRANT ALL PRIVILEGES ON *.* TO 'playground'@'localhost';"
40
  mysql -e "FLUSH PRIVILEGES;"
41