github.com/canhui/fabric_ca2_2@v2.0.0-alpha+incompatible/images/fabric-ca-fvt/payload/postgres_setup.sh (about) 1 #!/bin/bash 2 RC=0 3 4 # Configure and start postgres 5 echo $PGUSER:$PGUSER | chpasswd 6 mkdir -p $PGDATA && chown $PGUSER:$PGUSER $PGDATA 7 su $PGUSER -c "/usr/lib/postgresql/$PGVER/bin/initdb -D $PGDATA" 8 su $PGUSER -c "/usr/lib/postgresql/$PGVER/bin/pg_ctl start -D $PGDATA" &&\ 9 sleep 10 &&\ 10 psql -U $PGUSER -h localhost -c "ALTER USER $PGUSER WITH PASSWORD '$PGPASSWORD';" &&\ 11 su $PGUSER -c "/usr/lib/postgresql/$PGVER/bin/pg_ctl stop" 12 let RC+=$? 13 echo "host all all 0.0.0.0/0 trust" >> ${PGDATA}/pg_hba.conf 14 echo "listen_addresses='*'" >> ${PGDATA}/postgresql.conf 15 # Enable TLS for postgres 16 cp $FABRIC_CA_DATA/$TLS_BUNDLE $PGDATA || let RC+=1 17 cp $FABRIC_CA_DATA/$TLS_SERVER_CERT $PGDATA || let RC+=1 18 cp $FABRIC_CA_DATA/$TLS_SERVER_KEY $PGDATA || let RC+=1 19 # postgres insists on restricted access to keys 20 chown $PGUSER.$PGUSER $PGDATA/*pem || let RC+=1 21 chmod 600 $PGDATA/FabricTlsServer*.pem || let RC+=1 22 sed -i "s/\(^[[:blank:]]*\)#*\([[:blank:]]*ssl[[:blank:]]*=[[:blank:]]*\).*/\1\2on/;\ 23 s/\(^[[:blank:]]*\)#*\([[:blank:]]*max_connections[[:blank:]]*=[[:blank:]]*\).*/\1\22000/;\ 24 s/\(^[[:blank:]]*\)#*\([[:blank:]]*ssl_cert_file[[:blank:]]*=[[:blank:]]*\).*/\1\2'$TLS_SERVER_CERT'/;\ 25 s/\(^[[:blank:]]*\)#*\([[:blank:]]*ssl_cert_file[[:blank:]]*=[[:blank:]]*\).*/\1\2'$TLS_SERVER_CERT'/;\ 26 s/\(^[[:blank:]]*\)#*\([[:blank:]]*ssl_key_file[[:blank:]]*=[[:blank:]]*\).*/\1\2'$TLS_SERVER_KEY'/;\ 27 s/\(^[[:blank:]]*\)#*\([[:blank:]]*ssl_ca_file[[:blank:]]*=[[:blank:]]*\).*/\1\2'$TLS_BUNDLE'/;\ 28 s/\(^[[:blank:]]*\)#*\([[:blank:]]*log_destination[[:blank:]]*=[[:blank:]]*\).*/\1\2'syslog'/;\ 29 s/\(^[[:blank:]]*\)#*\([[:blank:]]*logging_collector[[:blank:]]*=[[:blank:]]*\).*/\1\2on/;\ 30 s/\(^[[:blank:]]*\)#*\([[:blank:]]*log_directory[[:blank:]]*=[[:blank:]]*\).*/\1\2'pg_log'/;\ 31 s/\(^[[:blank:]]*\)#*\([[:blank:]]*log_filename[[:blank:]]*=[[:blank:]]*\).*/\1\2'postgresql-%Y-%m-%d_%H%M%S.log'/;\ 32 s/\(^[[:blank:]]*\)#*\([[:blank:]]*log_file_mode[[:blank:]]*=[[:blank:]]*\).*/\1\2'0644'/;\ 33 s/\(^[[:blank:]]*\)#*\([[:blank:]]*log_truncate_on_rotation[[:blank:]]*=[[:blank:]]*\).*/\1\2on/;\ 34 s/\(^[[:blank:]]*\)#*\([[:blank:]]*log_rotation_size[[:blank:]]*=[[:blank:]]*\).*/\1\210MB/;\ 35 s/\(^[[:blank:]]*\)#*\([[:blank:]]*syslog_facility[[:blank:]]*=[[:blank:]]*\).*/\1\2'LOCAL0'/;\ 36 s/\(^[[:blank:]]*\)#*\([[:blank:]]*syslog_ident[[:blank:]]*=[[:blank:]]*\).*/\1\2'$PGUSER'/" $PGDATA/postgresql.conf || let RC+=1 37 38 # Generate version-agnostic postgres command 39 ln -s /usr/lib/postgresql/$PGVER/bin/postgres /usr/local/bin/postgres && chmod 777 /usr/local/bin/postgres || let RC+=1 40 41 exit $RC