Fixed initial setup not creating config files

This commit is contained in:
Daniel Winzen
2019-02-23 07:11:19 +01:00
parent a520c987e6
commit 31c6020608

View File

@ -140,17 +140,18 @@ if(!@$version=$db->query("SELECT value FROM settings WHERE setting='version';"))
} }
$stmt=$db->prepare("UPDATE settings SET value=? WHERE setting='version';"); $stmt=$db->prepare("UPDATE settings SET value=? WHERE setting='version';");
$stmt->execute([DBVERSION]); $stmt->execute([DBVERSION]);
foreach(PHP_VERSIONS as $version){ }
if(!file_exists("/etc/php/$version/fpm/conf.d/")){ foreach(PHP_VERSIONS as $version){
mkdir("/etc/php/$version/fpm/conf.d/", 0755, true); if(!file_exists("/etc/php/$version/fpm/conf.d/")){
} mkdir("/etc/php/$version/fpm/conf.d/", 0755, true);
file_put_contents("/etc/php/$version/fpm/conf.d/99-hosting.ini", PHP_CONFIG); }
if(!file_exists("/etc/php/$version/cli/conf.d/")){ file_put_contents("/etc/php/$version/fpm/conf.d/99-hosting.ini", PHP_CONFIG);
mkdir("/etc/php/$version/cli/conf.d/", 0755, true); if(!file_exists("/etc/php/$version/cli/conf.d/")){
} mkdir("/etc/php/$version/cli/conf.d/", 0755, true);
file_put_contents("/etc/php/$version/cli/conf.d/99-hosting.ini", PHP_CONFIG); }
foreach(SERVICE_INSTANCES as $instance){ file_put_contents("/etc/php/$version/cli/conf.d/99-hosting.ini", PHP_CONFIG);
$fpm_config = "[global] foreach(SERVICE_INSTANCES as $instance){
$fpm_config = "[global]
pid = /run/php/php$version-fpm-$instance.pid pid = /run/php/php$version-fpm-$instance.pid
error_log = /var/log/php$version-fpm-$instance.log error_log = /var/log/php$version-fpm-$instance.log
process_control_timeout = 10 process_control_timeout = 10
@ -158,12 +159,12 @@ emergency_restart_threshold = 10
emergency_restart_interval = 10m emergency_restart_interval = 10m
include=/etc/php/$version/fpm/pool.d/$instance/*.conf include=/etc/php/$version/fpm/pool.d/$instance/*.conf
"; ";
file_put_contents("/etc/php/$version/fpm/php-fpm-$instance.conf", $fpm_config); file_put_contents("/etc/php/$version/fpm/php-fpm-$instance.conf", $fpm_config);
if(!file_exists("/etc/php/$version/fpm/pool.d/$instance/")){ if(!file_exists("/etc/php/$version/fpm/pool.d/$instance/")){
mkdir("/etc/php/$version/fpm/pool.d/$instance/", 0755, true); mkdir("/etc/php/$version/fpm/pool.d/$instance/", 0755, true);
}
} }
$fpm_config = "[global] }
$fpm_config = "[global]
pid = /run/php/php$version-fpm.pid pid = /run/php/php$version-fpm.pid
error_log = /var/log/php$version-fpm.log error_log = /var/log/php$version-fpm.log
process_control_timeout = 10 process_control_timeout = 10
@ -171,8 +172,8 @@ emergency_restart_threshold = 10
emergency_restart_interval = 10m emergency_restart_interval = 10m
include=/etc/php/$version/fpm/pool.d/*.conf include=/etc/php/$version/fpm/pool.d/*.conf
"; ";
file_put_contents("/etc/php/$version/fpm/php-fpm.conf", $fpm_config); file_put_contents("/etc/php/$version/fpm/php-fpm.conf", $fpm_config);
$pool_config = "[hosting] $pool_config = "[hosting]
user = www-data user = www-data
group = www-data group = www-data
listen = /run/php/$version-hosting listen = /run/php/$version-hosting
@ -232,31 +233,30 @@ pm.max_spare_servers = 3
php_admin_value[mysqli.allow_persistent] = On php_admin_value[mysqli.allow_persistent] = On
php_admin_value[open_basedir] = /usr/share/adminer:/tmp php_admin_value[open_basedir] = /usr/share/adminer:/tmp
"; ";
if(!file_exists("/etc/php/$version/fpm/pool.d/")){ if(!file_exists("/etc/php/$version/fpm/pool.d/")){
mkdir("/etc/php/$version/fpm/pool.d/", 0755, true); mkdir("/etc/php/$version/fpm/pool.d/", 0755, true);
}
file_put_contents("/etc/php/$version/fpm/pool.d/www.conf", $pool_config);
exec("service php$version-fpm@default reload");
} }
echo "Updating chroots, this might take a while…\n"; file_put_contents("/etc/php/$version/fpm/pool.d/www.conf", $pool_config);
exec('/var/www/setup_chroot.sh /var/www'); exec("service php$version-fpm@default reload");
$stmt=$db->query('SELECT system_account FROM users;'); }
$shell = ENABLE_SHELL_ACCESS ? '/bin/bash' : '/usr/sbin/nologin'; echo "Updating chroots, this might take a while…\n";
while($tmp=$stmt->fetch(PDO::FETCH_ASSOC)){ exec('/var/www/setup_chroot.sh /var/www');
echo "Updating chroot for user $tmp[system_account]\n"; $stmt=$db->query('SELECT system_account FROM users;');
exec('usermod -s ' . escapeshellarg($shell) . ' ' . escapeshellarg($tmp['system_account'])); $shell = ENABLE_SHELL_ACCESS ? '/bin/bash' : '/usr/sbin/nologin';
exec('/var/www/setup_chroot.sh ' . escapeshellarg('/home/'.$tmp['system_account'])); while($tmp=$stmt->fetch(PDO::FETCH_ASSOC)){
exec('grep ' . escapeshellarg($tmp['system_account']) . ' /etc/passwd >> ' . escapeshellarg("/home/$tmp[system_account]/etc/passwd")); echo "Updating chroot for user $tmp[system_account]\n";
} exec('usermod -s ' . escapeshellarg($shell) . ' ' . escapeshellarg($tmp['system_account']));
file_put_contents('/etc/nginx/sites-enabled/default', NGINX_DEFAULT); exec('/var/www/setup_chroot.sh ' . escapeshellarg('/home/'.$tmp['system_account']));
if(!file_exists("/etc/nginx/streams-enabled/")){ exec('grep ' . escapeshellarg($tmp['system_account']) . ' /etc/passwd >> ' . escapeshellarg("/home/$tmp[system_account]/etc/passwd"));
mkdir("/etc/nginx/streams-enabled/", 0755, true); }
} file_put_contents('/etc/nginx/sites-enabled/default', NGINX_DEFAULT);
file_put_contents('/etc/nginx/streams-enabled/default', "server { if(!file_exists("/etc/nginx/streams-enabled/")){
mkdir("/etc/nginx/streams-enabled/", 0755, true);
}
file_put_contents('/etc/nginx/streams-enabled/default', "server {
listen unix:/var/www/var/run/mysqld/mysqld.sock; listen unix:/var/www/var/run/mysqld/mysqld.sock;
proxy_pass unix:/var/run/mysqld/mysqld.sock; proxy_pass unix:/var/run/mysqld/mysqld.sock;
}"); }");
exec("service nginx reload"); exec("service nginx reload");
$db->exec('UPDATE service_instances SET reload=1;'); $db->exec('UPDATE service_instances SET reload=1;');
echo "Done - Database and files have been updated to the latest version :)\n"; echo "Done - Database and files have been updated to the latest version :)\n";
}