bpandey23 commited on
Commit
3bd145b
1 Parent(s): 193844b

Update entrypoint.sh

Browse files
Files changed (1) hide show
  1. entrypoint.sh +9 -24
entrypoint.sh CHANGED
@@ -1,26 +1,11 @@
1
  #!/bin/bash
2
 
3
- # Set the environment variables for the PostgreSQL database
4
- export POSTGRES_DB=my_database
5
- export POSTGRES_USER=my_username
6
- export POSTGRES_PASSWORD=my_password
7
-
8
- # Create the PostgreSQL database and user
9
- su - postgres -c "psql -c \"CREATE DATABASE $POSTGRES_DB;\""
10
- su - postgres -c "psql -c \"CREATE USER $POSTGRES_USER WITH PASSWORD '$POSTGRES_PASSWORD';\""
11
- su - postgres -c "psql -c \"GRANT ALL PRIVILEGES ON DATABASE $POSTGRES_DB TO $POSTGRES_USER;\""
12
-
13
- # Create a table and insert sample data
14
- su - postgres -c "psql -d $POSTGRES_DB -c \"
15
- CREATE TABLE users (
16
- id SERIAL PRIMARY KEY,
17
- name VARCHAR(50) NOT NULL,
18
- email VARCHAR(50) UNIQUE NOT NULL
19
- );
20
- INSERT INTO users (name, email) VALUES
21
- ('John Doe', '[email protected]'),
22
- ('Jane Smith', '[email protected]');
23
- \""
24
-
25
- # Start the PostgreSQL service
26
- exec postgres
 
1
  #!/bin/bash
2
 
3
+ # Check if the PostgreSQL data directory is empty
4
+ if [ -z "$(ls -A /var/lib/postgresql/data)" ]; then
5
+ echo "Initializing PostgreSQL database..."
6
+ /usr/lib/postgresql/*/bin/initdb -D /var/lib/postgresql/data
7
+ fi
8
+
9
+ # Start the PostgreSQL server
10
+ exec /usr/bin/postgres -D /var/lib/postgresql/data
11
+ echo "server started successfully............."