Current File : /home/inlingua/public_html/decay_sym/root/var/softaculous/apps/nginx/3/update.php
<?php

add_filter('nginx_update_dont_remove', 'nginx_update_dont_remove', 10, 1);

function nginx_update_dont_remove(){
	return true;
}


function __nginx_pre_update(){
	
	global $globals;
	
	// Create a directory to hold all the conf files
	if(!file_exists($globals['var_tmp'].'/nginx_confs_backup')){
		mkdir($globals['var_tmp'].'/nginx_confs_backup', 0750, 1);
	}

	// Copy the actual conf files to new location
	vexec('cp -r '.NGINX_CONFD.'* '.$globals['var_tmp'].'/nginx_confs_backup/');
	
	vexec('systemctl stop nginx');
	vexec('systemctl disable nginx');
	
	if(is_app_installed('varnish', 1) && !empty($globals['VARNISH_PORT'])){
		kill_by_port($globals['VARNISH_PORT']);
	}else{
		kill_by_port(80);
	}
	
}

function __nginx_post_update(){
	
	global $globals,  $W;
	
	if(!is_file(NGINX_WAPP.'/nginx-x86_64.tar.gz')){
		$W->downloadapp(18, 0, 0, 1);
	}
	
	vexec('tar -zxf '.NGINX_WAPP.'/nginx-x86_64.tar.gz -C /usr/local/apps/');
	
	// Copy Conf files
	copy(__DIR__.'/nginx.conf', NGINX_ETC.'nginx.conf');
	
	if(file_exists($globals['var_tmp'].'/nginx_confs_backup')){
		
		// Make the CONF Folder
		@mkdir(NGINX_ETC.'conf.d', 0755);
		
		// Copy the conf file to actual location
		vexec('yes | cp -r '.$globals['var_tmp'].'/nginx_confs_backup/* '.NGINX_CONFD);
	}
	
	mkdir(NGINX_ETC.'html/suspended/');
	copy(NGINX_WAPP.'/suspended.html', NGINX_ETC.'html/suspended/index.html');
	copy(NGINX_WAPP.'/nginx', NGINX_APP.'bin/nginxctl');
	
	// Delete the directory once the files are copied
	vexec('rm -rf '.$globals['var_tmp'].'/nginx_confs_backup');
	
	// CRONS might start other webserver on port 80
	if(is_app_installed('varnish', 1) && !empty($globals['VARNISH_PORT'])){
		kill_by_port($globals['VARNISH_PORT']);
	}else{
		kill_by_port(80);
	}
	
	vexec('systemctl daemon-reload');
	vexec('systemctl enable nginx');
	vexec('systemctl restart nginx');
	
	nginx_modsec_rebuild();
	
}