mirror of
https://github.com/lucaspalomodevelop/core.git
synced 2026-03-15 00:54:41 +00:00
proxy: provide mutable force restart hook for reconfigure
It's a bit tricky to get this right. More testing needed, but shouldn't intruduce regressions. It could, but if the code works it will not. ;)
This commit is contained in:
parent
99c783a934
commit
8d569f2cb7
@ -105,7 +105,6 @@ abstract class ApiMutableServiceControllerBase extends ApiControllerBase
|
||||
public function startAction()
|
||||
{
|
||||
if ($this->request->isPost()) {
|
||||
// close session for long running action
|
||||
$this->sessionClose();
|
||||
$backend = new Backend();
|
||||
$response = $backend->configdRun(escapeshellarg(static::$internalServiceName) . ' start');
|
||||
@ -122,7 +121,6 @@ abstract class ApiMutableServiceControllerBase extends ApiControllerBase
|
||||
public function stopAction()
|
||||
{
|
||||
if ($this->request->isPost()) {
|
||||
// close session for long running action
|
||||
$this->sessionClose();
|
||||
$backend = new Backend();
|
||||
$response = $backend->configdRun(escapeshellarg(static::$internalServiceName) . ' stop');
|
||||
@ -139,7 +137,6 @@ abstract class ApiMutableServiceControllerBase extends ApiControllerBase
|
||||
public function restartAction()
|
||||
{
|
||||
if ($this->request->isPost()) {
|
||||
// close session for long running action
|
||||
$this->sessionClose();
|
||||
$backend = new Backend();
|
||||
$response = $backend->configdRun(escapeshellarg(static::$internalServiceName) . ' restart');
|
||||
@ -149,26 +146,39 @@ abstract class ApiMutableServiceControllerBase extends ApiControllerBase
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* reconfigure force restart check, return zero for soft-reload
|
||||
*/
|
||||
protected function reconfigureForceRestart()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* reconfigure, generate config and reload
|
||||
*/
|
||||
public function reconfigureAction()
|
||||
{
|
||||
if ($this->request->isPost()) {
|
||||
// close session for long running action
|
||||
$this->sessionClose();
|
||||
|
||||
$model = $this->getModel();
|
||||
$backend = new Backend();
|
||||
|
||||
$this->stopAction();
|
||||
if ((string)$model->getNodeByReference(static::$internalServiceEnabled) != '1' ||
|
||||
$this->reconfigureForceRestart()) {
|
||||
$backend->configdRun(escapeshellarg(static::$internalServiceName) . ' stop');
|
||||
}
|
||||
|
||||
// generate template
|
||||
$backend->configdRun('template reload ' . escapeshellarg(static::$internalServiceTemplate));
|
||||
|
||||
// (re)start daemon
|
||||
if ((string)$model->getNodeByReference(static::$internalServiceEnabled) == '1') {
|
||||
$this->startAction();
|
||||
$runStatus = $this->statusAction();
|
||||
if ($runStatus['status'] != 'running') {
|
||||
$backend->configdRun(escapeshellarg(static::$internalServiceName) . ' start');
|
||||
} else {
|
||||
$backend->configdRun(escapeshellarg(static::$internalServiceName) . ' reconfigure');
|
||||
}
|
||||
}
|
||||
|
||||
return array('status' => 'ok');
|
||||
|
||||
@ -43,51 +43,17 @@ class ServiceController extends ApiMutableServiceControllerBase
|
||||
static $internalServiceTemplate = 'OPNsense/Proxy';
|
||||
static $internalServiceName = 'proxy';
|
||||
|
||||
/**
|
||||
* reconfigure squid, generate config and reload
|
||||
*/
|
||||
public function reconfigureAction()
|
||||
protected function reconfigureForceRestart()
|
||||
{
|
||||
if ($this->request->isPost()) {
|
||||
// close session for long running action
|
||||
$this->sessionClose();
|
||||
$mdlProxy = new Proxy();
|
||||
|
||||
$force_restart = false;
|
||||
// some operations can not be performed by a squid -k reconfigure,
|
||||
// try to determine if we need a stop/start here
|
||||
$prev_sslbump_cert = trim(@file_get_contents('/var/squid/ssl_crtd.id'));
|
||||
$prev_cache_active = !empty(trim(@file_get_contents('/var/squid/cache/active')));
|
||||
|
||||
$mdlProxy = new Proxy();
|
||||
$backend = new Backend();
|
||||
|
||||
$runStatus = $this->statusAction();
|
||||
|
||||
// some operations can not be performed by a squid -k reconfigure,
|
||||
// try to determine if we need a stop/start here
|
||||
$prev_sslbump_cert = trim(@file_get_contents('/var/squid/ssl_crtd.id'));
|
||||
$prev_cache_active = !empty(trim(@file_get_contents('/var/squid/cache/active')));
|
||||
$force_restart = (((string)$mdlProxy->forward->sslcertificate) != $prev_sslbump_cert) ||
|
||||
(!empty((string)$mdlProxy->general->cache->local->enabled) != $prev_cache_active);
|
||||
|
||||
// stop squid when disabled
|
||||
if ($runStatus['status'] == "running" &&
|
||||
($mdlProxy->general->enabled->__toString() == 0 || $force_restart)) {
|
||||
$this->stopAction();
|
||||
}
|
||||
|
||||
// generate template
|
||||
$backend->configdRun('template reload OPNsense/Proxy');
|
||||
|
||||
// (res)start daemon
|
||||
if ($mdlProxy->general->enabled->__toString() == 1) {
|
||||
if ($runStatus['status'] == "running" && !$force_restart) {
|
||||
$backend->configdRun("proxy reconfigure");
|
||||
} else {
|
||||
$this->startAction();
|
||||
}
|
||||
}
|
||||
|
||||
return array("status" => "ok");
|
||||
} else {
|
||||
return array("status" => "failed");
|
||||
}
|
||||
return (((string)$mdlProxy->forward->sslcertificate) != $prev_sslbump_cert) ||
|
||||
(!empty((string)$mdlProxy->general->cache->local->enabled) != $prev_cache_active);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user