@ -803,11 +803,11 @@ sub configure_pgsql
my $ initialized = 0 ;
my $ running = $ anvil - > System - > check_daemon ( { debug = > $ debug , daemon = > $ anvil - > data - > { sys } { daemon } { postgresql } } ) ;
$ anvil - > Log - > variables ( { source = > $ THIS_FILE , line = > __LINE__ , level = > $ debug , list = > { running = > $ running } } ) ;
if ( ( not $ running ) && ( not - e $ anvil - > data - > { path } { configs } { 'pg_hba.conf' } ) )
if ( not - e $ anvil - > data - > { path } { configs } { 'pg_hba.conf' } )
{
# Initialize. Record that we did so, so that we know to start the daemon.
my ( $ output , $ return_code ) = $ anvil - > System - > call ( { debug = > $ debug , shell_call = > $ anvil - > data - > { path } { exe } { 'postgresql-setup' } . " initdb" , source = > $ THIS_FILE , line = > __LINE__ } ) ;
$ anvil - > Log - > variables ( { source = > $ THIS_FILE , line = > __LINE__ , level = > $ debug , list = > { output = > $ output , return_code = > $ return_code } } ) ;
my ( $ output , $ return_code ) = $ anvil - > System - > call ( { debug = > 1 , shell_call = > $ anvil - > data - > { path } { exe } { 'postgresql-setup' } . " initdb" , source = > $ THIS_FILE , line = > __LINE__ } ) ;
$ anvil - > Log - > variables ( { source = > $ THIS_FILE , line = > __LINE__ , level = > 1 , list = > { output = > $ output , return_code = > $ return_code } } ) ;
# Did it succeed?
if ( not - e $ anvil - > data - > { path } { configs } { 'pg_hba.conf' } )
@ -911,7 +911,7 @@ sub configure_pgsql
{
# Back up the existing one, if needed.
my $ pg_hba_backup = $ anvil - > data - > { path } { directories } { backups } . "/pgsql/pg_hba.conf" ;
$ anvil - > Log - > variables ( { source = > $ THIS_FILE , line = > __LINE__ , level = > $ debug , list = > { pg_hba_backup = > $ pg_hba_backup } } ) ;
$ anvil - > Log - > variables ( { source = > $ THIS_FILE , line = > __LINE__ , level = > 1 , list = > { pg_hba_backup = > $ pg_hba_backup } } ) ;
if ( not - e $ pg_hba_backup )
{
$ anvil - > Storage - > copy_file ( {
@ -940,7 +940,7 @@ sub configure_pgsql
{
# Start the daemon.
my $ return_code = $ anvil - > System - > start_daemon ( { daemon = > $ anvil - > data - > { sys } { daemon } { postgresql } } ) ;
$ anvil - > Log - > variables ( { source = > $ THIS_FILE , line = > __LINE__ , level = > $ debug , list = > { return_code = > $ return_code } } ) ;
$ anvil - > Log - > variables ( { source = > $ THIS_FILE , line = > __LINE__ , level = > 1 , list = > { return_code = > $ return_code } } ) ;
if ( $ return_code eq "0" )
{
# Started the daemon.
@ -958,7 +958,7 @@ sub configure_pgsql
{
# Reload
my $ return_code = $ anvil - > System - > start_daemon ( { daemon = > $ anvil - > data - > { sys } { daemon } { postgresql } } ) ;
$ anvil - > Log - > variables ( { source = > $ THIS_FILE , line = > __LINE__ , level = > $ debug , list = > { return_code = > $ return_code } } ) ;
$ anvil - > Log - > variables ( { source = > $ THIS_FILE , line = > __LINE__ , level = > 1 , list = > { return_code = > $ return_code } } ) ;
if ( $ return_code eq "0" )
{
# Reloaded the daemon.
@ -971,6 +971,9 @@ sub configure_pgsql
}
}
# Do user and DB checks only if we're made a change above.
if ( ( $ initialized ) or ( $ update_postgresql_file ) or ( $ update_pg_hba_file ) )
{
# Create the .pgpass file, if needed.
my $ created_pgpass = 0 ;
$ anvil - > Log - > variables ( { source = > $ THIS_FILE , line = > __LINE__ , level = > $ debug , secure = > 1 , list = > {
@ -1117,6 +1120,7 @@ sub configure_pgsql
$ anvil - > Log - > entry ( { source = > $ THIS_FILE , line = > __LINE__ , level = > 0 , priority = > "alert" , key = > "log_0107" } ) ;
}
}
}
# Make sure the psql TCP port is open.
$ anvil - > data - > { database } { $ uuid } { port } = 5432 if not $ anvil - > data - > { database } { $ uuid } { port } ;
@ -1314,6 +1318,23 @@ sub connect
$ anvil - > Log - > variables ( { source = > $ THIS_FILE , line = > __LINE__ , level = > $ debug , list = > { check_for_resync = > $ check_for_resync } } ) ;
}
# If we're a Striker, see if we're configured.
my $ local_host_type = $ anvil - > Get - > host_type ( ) ;
my $ local_host_uuid = $ anvil - > Get - > host_uuid ( ) ;
$ anvil - > Log - > variables ( { source = > $ THIS_FILE , line = > __LINE__ , level = > $ debug , list = > {
local_host_type = > $ local_host_type ,
local_host_uuid = > $ local_host_uuid ,
check_if_configured = > $ check_if_configured ,
real_uid = > $< ,
effective_uid = > $> ,
} } ) ;
# If requested, and if running with root access, set it up (or update it) if needed.
# This method just returns if nothing is needed.
if ( ( $ local_host_type eq "striker" ) && ( $ check_if_configured ) && ( $< == 0 ) && ( $> == 0 ) )
{
$ anvil - > Database - > configure_pgsql ( { debug = > 2 , uuid = > $ local_host_uuid } ) ;
}
# Now setup or however-many connections
my $ seen_connections = [] ;
my $ failed_connections = [] ;
@ -1636,24 +1657,12 @@ sub connect
}
# Before we try to connect, see if this is a local database and, if so, make sure it's setup.
my $ is_local = $ anvil - > Network - > is_local ( { debug = > $ debug , host = > $ host } ) ;
my $ is_local = $ anvil - > Network - > is_local ( { debug = > 2 , host = > $ host } ) ;
$ anvil - > Log - > variables ( { source = > $ THIS_FILE , line = > __LINE__ , level = > $ debug , list = > { is_local = > $ is_local } } ) ;
if ( $ is_local )
{
$ anvil - > data - > { sys } { database } { read_uuid } = $ uuid ;
$ anvil - > Log - > variables ( { source = > $ THIS_FILE , line = > __LINE__ , level = > $ debug , list = > { "sys::database::read_uuid" = > $ anvil - > data - > { sys } { database } { read_uuid } } } ) ;
# If requested, and if running with root access, set it up (or update it) if needed.
# This method just returns if nothing is needed.
$ anvil - > Log - > variables ( { source = > $ THIS_FILE , line = > __LINE__ , level = > $ debug , list = > {
check_if_configured = > $ check_if_configured ,
real_uid = > $< ,
effective_uid = > $> ,
} } ) ;
if ( ( $ check_if_configured ) && ( $< == 0 ) && ( $> == 0 ) )
{
$ anvil - > Database - > configure_pgsql ( { debug = > $ debug , uuid = > $ uuid } ) ;
}
}
elsif ( not $ anvil - > data - > { sys } { database } { read_uuid } )
{
@ -1699,8 +1708,6 @@ sub connect
}
# If we're a striker and no connections were found, start our database.
my $ local_host_type = $ anvil - > Get - > host_type ( ) ;
my $ local_host_uuid = $ anvil - > Get - > host_uuid ( ) ;
if ( ( $ local_host_type eq "striker" ) && ( not $ anvil - > data - > { sys } { database } { connections } ) )
{
# Tell the user we're going to try to load and start.