diff --git a/sysutils/nut/src/opnsense/mvc/app/controllers/OPNsense/Nut/Api/ServiceController.php b/sysutils/nut/src/opnsense/mvc/app/controllers/OPNsense/Nut/Api/ServiceController.php index 174623cee..43e07c267 100644 --- a/sysutils/nut/src/opnsense/mvc/app/controllers/OPNsense/Nut/Api/ServiceController.php +++ b/sysutils/nut/src/opnsense/mvc/app/controllers/OPNsense/Nut/Api/ServiceController.php @@ -28,118 +28,15 @@ namespace OPNsense\Nut\Api; -use \OPNsense\Base\ApiControllerBase; -use \OPNsense\Core\Backend; -use \OPNsense\Nut\Nut; +use OPNsense\Base\ApiMutableServiceControllerBase; -class ServiceController extends ApiControllerBase +class ServiceController extends ApiMutableServiceControllerBase { + static protected $internalServiceClass = '\OPNsense\Nut\Nut'; + static protected $internalServiceTemplate = 'OPNsense/Nut'; + static protected $internalServiceEnabled = 'general.enabled'; + static protected $internalServiceName = 'nut'; - /** - * restart nut service - * @return array - */ - public function restartAction() - { - if ($this->request->isPost()) { - // close session for long running action - $this->sessionClose(); - $backend = new Backend(); - $response = $backend->configdRun('nut restart'); - return array('response' => $response); - } else { - return array('response' => array()); - } - } - - /** - * retrieve status of nut - * @return array - * @throws \Exception - */ - public function statusAction() - { - $backend = new Backend(); - $nut = new Nut(); - $response = $backend->configdRun('nut status'); - - if (strpos($response, 'not running') > 0) { - if ((string)$nut->general->enabled == 1) { - $status = 'stopped'; - } else { - $status = 'disabled'; - } - } elseif (strpos($response, 'is running') > 0) { - $status = 'running'; - } elseif ((string)$nut->general->enabled == 0) { - $status = 'disabled'; - } else { - $status = 'unknown'; - } - - return array('status' => $status); - } - - /** - * reconfigure nut, generate config and reload - */ - public function reconfigureAction() - { - if ($this->request->isPost()) { - // close session for long running action - $this->sessionClose(); - - $nut = new Nut(); - $backend = new Backend(); - - $this->stopAction(); - - // generate template - $backend->configdRun('template reload OPNsense/Nut'); - - // (re)start daemon - if ((string)$nut->general->enabled == '1') { - $this->startAction(); - } - - return array('status' => 'ok'); - } else { - return array('status' => 'failed'); - } - } - - /** - * stop nut service - * @return array - */ - public function stopAction() - { - if ($this->request->isPost()) { - // close session for long running action - $this->sessionClose(); - $backend = new Backend(); - $response = $backend->configdRun('nut stop'); - return array('response' => $response); - } else { - return array('response' => array()); - } - } - /** - * start nut service - * @return array - */ - public function startAction() - { - if ($this->request->isPost()) { - // close session for long running action - $this->sessionClose(); - $backend = new Backend(); - $response = $backend->configdRun('nut start'); - return array('response' => $response); - } else { - return array('response' => array()); - } - } public function upsstatusAction() { $backend = new Backend(); diff --git a/sysutils/nut/src/opnsense/mvc/app/views/OPNsense/Nut/index.volt b/sysutils/nut/src/opnsense/mvc/app/views/OPNsense/Nut/index.volt index d5c60663a..3c3e4d86f 100644 --- a/sysutils/nut/src/opnsense/mvc/app/views/OPNsense/Nut/index.volt +++ b/sysutils/nut/src/opnsense/mvc/app/views/OPNsense/Nut/index.volt @@ -57,13 +57,14 @@ saveFormToEndpoint(url="/api/nut/settings/set", formid=frm_id, callback_ok=function(){ // on correct save, perform restart, set progress animation when reloading $("#"+frm_id+"_progress").addClass("fa fa-spinner fa-pulse"); - - ajaxCall(url="/api/nut/service/restart", sendData={}, callback=function(data,status){ - // when done, disable progress animation. - $("#"+frm_id+"_progress").removeClass("fa fa-spinner fa-pulse"); - ajaxCall(url="/api/nut/service/status", sendData={}, callback=function(data,status) { - updateServiceStatusUI(data['status']); - }); + ajaxCall(url="/api/nut/service/reconfigure", sendData={}, callback=function(data,status){ + ajaxCall(url="/api/nut/service/restart", sendData={}, callback=function(data,status){ + // when done, disable progress animation. + $("#"+frm_id+"_progress").removeClass("fa fa-spinner fa-pulse"); + ajaxCall(url="/api/nut/service/status", sendData={}, callback=function(data,status) { + updateServiceStatusUI(data['status']); + }); + }); }); }); }); diff --git a/sysutils/nut/src/opnsense/service/conf/actions.d/actions_nut.conf b/sysutils/nut/src/opnsense/service/conf/actions.d/actions_nut.conf index 726dc3136..c43b77296 100644 --- a/sysutils/nut/src/opnsense/service/conf/actions.d/actions_nut.conf +++ b/sysutils/nut/src/opnsense/service/conf/actions.d/actions_nut.conf @@ -5,7 +5,7 @@ type:script message:starting nut [stop] -command:/usr/local/etc/rc.d/nut stop;/usr/local/etc/rc.d/nut_upsmon stop;exit 0 +command:/usr/local/etc/rc.d/nut stop;/usr/local/etc/rc.d/nut_upsmon stop parameters: type:script message:stopping nut