I'm developing the flashmemory plugin (actually openmediavault-flashmemory-folder2ram branch of openmediavault-flashmemory).
But I'm a bit puzzled and cannot get past the following issue.
I have a secondary package called folder2ram, the openmediavault-flashmemory fork is supposed to run a "folder2ram -generate && folder2ram -mountall" when the plugin is enabled, and "folder2ram -clean" when the plugin is disabled.
Checking the "enable" checkbox, clicking on Save and then confirming gives the correct result:
the config is generated and folder2ram is started.
unchecking the "enable" checkbox, clicking on Save and then confirming does not have any effect. It should trigger a "folder2ram -clean" command.
I tried to copy around some code but I'm not sure what its function is, can someone tell me what I'm missing here?
The /usr/share/openmediavault/engined/module/flashmemory.inc
is pasted below, the full source of the branch is here https://github.com/OpenMediaVa…lt-flashmemory-folder2ram
<?php
/**
* Copyright (C) 2015 OpenMediaVault Plugin Developers
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
require_once "openmediavault/config.inc";
require_once "openmediavault/error.inc";
require_once "openmediavault/initscript.inc";
require_once "openmediavault/module.inc";
require_once "openmediavault/util.inc";
class OMVModuleFlashmemory extends OMVModuleServiceAbstract implements
OMVINotifyListener
{
public function getName()
{
return "flashmemory";
}
private function getPluginName()
{
return strtolower( $this->getName() );
}
private function getServiceName()
{
return "folder2ram";
}
private function getXPath()
{
return sprintf( "//services/%s", $this->getPluginName() );
}
private function getEventMessagePath()
{
return sprintf( "org.openmediavault.services.%s", $this->getPluginName() );
}
public function applyConfig()
{
$cmd = sprintf("omv-mkconf %s 2>&1", $this->getName());
if (0 !== $this->exec($cmd, $output)) {
throw new OMVException(
OMVErrorMsg::E_EXEC_FAILED,
$cmd,
implode("\n", $output)
);
}
}
public function startService()
{
global $xmlConfig;
// when (if) OMV runs these commands, this will power up folder2ram
$cmd = sprintf("folder2ram -refresh 2>&1 && folder2ram -mountall 2>&1", $this->getName());
if (0 !== $this->exec($cmd, $output)) {
throw new OMVException(
OMVErrorMsg::E_EXEC_FAILED,
$cmd,
implode("\n", $output)
);
}
$object = $xmlConfig->get($this->getXPath());
if (is_null($object)) {
throw new OMVException(
OMVErrorMsg::E_CONFIG_GET_OBJECT_FAILED,
$this->getXPath()
);
}
if (!boolval($object["enable"])) {
return;
}
// $initd = new OMVSysVInitScript($this->getServiceName(), true);
// $initd->exec();
}
public function stopService()
{
// $initd = new OMVSysVInitScript($this->getServiceName());
// $initd->exec();
// when (if) OMV runs these commands, it SHOULD power down folder2ram, but it DOES NOT do it.
$cmd = sprintf("folder2ram -clean 2>&1", $this->getName());
if (0 !== $this->exec($cmd, $output)) {
throw new OMVException(
OMVErrorMsg::E_EXEC_FAILED,
$cmd,
implode("\n", $output)
);
}
}
public function bindListeners(OMVNotifyDispatcher $dispatcher)
{
$moduleMgr = &OMVModuleMgr::getInstance();
$dispatcher->addListener(
OMV_NOTIFY_MODIFY,
$this->getEventMessagePath(),
array($this, "setDirty")
);
}
}
// Register module
$moduleMgr = &OMVModuleMgr::getInstance();
$moduleMgr->registerModule(new OMVModuleFlashmemory());
?>
Alles anzeigen