|
1 | 1 | #!/bin/bash |
2 | 2 | set -e |
3 | 3 |
|
4 | | -# Install grpcurl if not already installed |
5 | | -if ! command -v grpcurl &> /dev/null; then |
6 | | - echo "grpcurl not found, installing..." |
7 | | - apt update && apt install -y curl \ |
8 | | - && curl -sSL https://github.com/fullstorydev/grpcurl/releases/download/v1.8.0/grpcurl_1.8.0_linux_x86_64.tar.gz | tar -xzv -C /usr/local/bin grpcurl |
9 | | -fi |
| 4 | +echo "🚀 Starting Try ToolJet container initialization..." |
10 | 5 |
|
11 | | -# Start Redis |
12 | | -service redis-server start |
| 6 | +# Configure PostgreSQL authentication |
| 7 | +echo "🔧 Configuring PostgreSQL authentication..." |
| 8 | +sed -i 's/^local\s\+all\s\+postgres\s\+\(peer\|md5\)/local all postgres trust/' /etc/postgresql/13/main/pg_hba.conf >/dev/null 2>&1 |
| 9 | +sed -i 's/^local\s\+all\s\+all\s\+\(peer\|md5\)/local all all trust/' /etc/postgresql/13/main/pg_hba.conf >/dev/null 2>&1 |
13 | 10 |
|
14 | | -# Start Postgres |
| 11 | +# Start PostgreSQL |
| 12 | +echo "📈 Starting PostgreSQL..." |
15 | 13 | service postgresql start |
16 | 14 |
|
17 | | -# Start Temporal Server (SQLite configuration) |
18 | | -echo "Starting Temporal Server..." |
19 | | -/usr/bin/temporal-server -r / -c /etc/temporal/ -e temporal-server start & |
| 15 | +# Wait until PostgreSQL is ready |
| 16 | +echo "⏳ Waiting for PostgreSQL..." |
| 17 | +until pg_isready -h localhost -p 5432; do |
| 18 | + echo "PostgreSQL not ready yet, retrying..." |
| 19 | + sleep 2 |
| 20 | +done |
| 21 | + |
| 22 | +# Create user and databases for Temporal |
| 23 | +echo "🔧 Creating Temporal DBs and user if needed..." |
| 24 | +psql -U postgres -tc "SELECT 1 FROM pg_roles WHERE rolname='tooljet'" | grep -q 1 || \ |
| 25 | +psql -U postgres -c "CREATE USER tooljet WITH PASSWORD 'postgres' SUPERUSER;" >/dev/null 2>&1 |
| 26 | + |
| 27 | +psql -U postgres -tc "SELECT 1 FROM pg_database WHERE datname = 'temporal'" | grep -q 1 || \ |
| 28 | +psql -U postgres -c "CREATE DATABASE temporal OWNER tooljet;" >/dev/null 2>&1 |
| 29 | + |
| 30 | +psql -U postgres -tc "SELECT 1 FROM pg_database WHERE datname = 'temporal_visibility'" | grep -q 1 || \ |
| 31 | +psql -U postgres -c "CREATE DATABASE temporal_visibility OWNER tooljet;" >/dev/null 2>&1 |
| 32 | + |
| 33 | +# Generate Temporal config |
| 34 | +echo "🔧 Generating Temporal config..." |
| 35 | +mkdir -p /etc/temporal/config |
| 36 | +if [ -f /etc/temporal/temporal-server.template.yaml ]; then |
| 37 | + envsubst < /etc/temporal/temporal-server.template.yaml > /etc/temporal/config/temporal-server.yaml >/dev/null 2>&1 |
| 38 | +else |
| 39 | + echo "❌ Missing template: /etc/temporal/temporal-server.template.yaml" |
| 40 | + exit 1 |
| 41 | +fi |
| 42 | + |
| 43 | +# Download schema files if not present |
| 44 | +if [ ! -d "/etc/temporal/schema/postgresql" ]; then |
| 45 | + echo "📥 Downloading Temporal schema files..." |
| 46 | + mkdir -p /etc/temporal/schema |
| 47 | + cd /tmp |
| 48 | + curl -sOL https://github.com/temporalio/temporal/archive/refs/tags/v1.28.0.tar.gz |
| 49 | + tar -xzf v1.28.0.tar.gz |
| 50 | + cp -r temporal-1.28.0/schema/postgresql /etc/temporal/schema/ |
| 51 | + rm -rf temporal-1.28.0 v1.28.0.tar.gz |
| 52 | + cd / |
| 53 | +fi |
| 54 | + |
| 55 | +rm -f /etc/temporal/temporal-sql-tool.yaml ~/.temporal/config.yaml |
| 56 | +mkdir -p /tmp/temporal |
| 57 | + |
| 58 | +# Set up schemas |
| 59 | +echo "🔧 Setting up Temporal schemas..." |
| 60 | +for db in temporal temporal_visibility; do |
| 61 | + PGPASSWORD=postgres /usr/bin/temporal-sql-tool --plugin postgres12 \ |
| 62 | + --ep "localhost" --port 5432 --user tooljet --password postgres \ |
| 63 | + --database $db setup-schema -v 0.0 >/dev/null 2>&1 |
| 64 | + |
| 65 | + schema_dir="/etc/temporal/schema/postgresql/v12" |
| 66 | + schema_type=$([ "$db" = "temporal" ] && echo "temporal" || echo "visibility") |
20 | 67 |
|
21 | | -# Export the PORT variable to be used by the application |
| 68 | + PGPASSWORD=postgres /usr/bin/temporal-sql-tool --plugin postgres12 \ |
| 69 | + --ep "localhost" --port 5432 --user tooljet --password postgres \ |
| 70 | + --database $db update-schema -d "$schema_dir/$schema_type/versioned" >/dev/null 2>&1 |
| 71 | +done |
| 72 | + |
| 73 | +echo "✅ Schema setup complete" |
| 74 | + |
| 75 | +# Export default port if not set |
22 | 76 | export PORT=${PORT:-80} |
23 | 77 |
|
| 78 | +# Start Temporal Server |
| 79 | +echo "🚀 Starting Temporal Server..." |
| 80 | +/usr/bin/temporal-server start >/dev/null 2>&1 & |
| 81 | +TEMPORAL_PID=$! |
| 82 | + |
24 | 83 | # Start Supervisor |
25 | | -exec supervisord -c /etc/supervisor/conf.d/supervisord.conf & |
| 84 | +echo "🚀 Starting Supervisor..." |
| 85 | +supervisord -c /etc/supervisor/conf.d/supervisord.conf & |
| 86 | +SUPERVISOR_PID=$! |
26 | 87 |
|
27 | | -# Wait for Temporal Server to be ready |
28 | | -echo "Waiting for Temporal Server to be ready..." |
29 | | -sleep 10 |
| 88 | +# Wait for Temporal to become ready |
| 89 | +echo "⏳ Waiting for Temporal..." |
| 90 | +for i in {1..30}; do |
| 91 | + if grpcurl -plaintext localhost:7233 grpc.health.v1.Health/Check >/dev/null 2>&1; then |
| 92 | + echo "✅ Temporal is ready" |
| 93 | + break |
| 94 | + fi |
| 95 | + sleep 2 |
| 96 | +done |
30 | 97 |
|
31 | 98 | # Check if namespace already exists |
32 | 99 | echo "Checking if Temporal namespace exists..." |
|
42 | 109 | }' localhost:7233 temporal.api.workflowservice.v1.WorkflowService/RegisterNamespace |
43 | 110 | fi |
44 | 111 |
|
45 | | -# Run the worker process (last step) |
46 | | -echo "Starting worker process..." |
47 | | -npm run worker:prod |
| 112 | +# Wait on background processes |
| 113 | +wait $TEMPORAL_PID $SUPERVISOR_PID |
| 114 | + |
| 115 | +# Start worker (last step) |
| 116 | +echo "🚀 Starting ToolJet worker..." |
| 117 | +npm --prefix server run worker:prod |
0 commit comments