refresh_from_lua();
}
+ /**
+ * Find a zavai script.
+ *
+ * ~/.zavai/NAME is searched first, then /usr/share/zavai/hooks/
+ *
+ * If the script is not found, NULL is returned
+ */
+ public string find_script(string name)
+ {
+ string candidate = homedir + "/" + name;
+ if (FileUtils.test(candidate, FileTest.EXISTS))
+ return candidate;
+ candidate = "/usr/share/zavai/hooks/" + name;
+ if (FileUtils.test(candidate, FileTest.EXISTS))
+ return candidate;
+ return null;
+ }
+
public void run_script(string command)
{
zavai.log.info("Run program: " + command);
public abstract class ScriptService : Service
{
+ protected string script;
+
protected bool script_start()
{
+ string script = zavai.config.find_script(name);
+ if (script == null)
+ {
+ zavai.log.error("Hook " + name + " does not exist");
+ return false;
+ }
try {
// Then run our own script
- zavai.config.run_script(zavai.config.homedir + "/" + name + " start");
+ zavai.config.run_script(script + " start");
return true;
} catch (Error e) {
- zavai.log.error("Running " + zavai.config.homedir + "/" + name + " start: " + e.message);
+ zavai.log.error("Running " + script + " start: " + e.message);
return false;
}
}
protected bool script_stop()
{
+ string script = zavai.config.find_script(name);
+ if (script == null)
+ {
+ zavai.log.error("Hook " + name + " does not exist");
+ return false;
+ }
try {
// Then run our own script
- zavai.config.run_script(zavai.config.homedir + "/" + name + " stop");
+ zavai.config.run_script(script + " stop");
return true;
} catch (Error e) {
- zavai.log.error("Running " + zavai.config.homedir + "/" + name + " stop: " + e.message);
+ zavai.log.error("Running " + script + " stop: " + e.message);
return false;
}
}
{
string std_out;
string std_err;
- string command = zavai.config.homedir + "/" + name + " status";
+ string script = zavai.config.find_script(name);
+ if (script == null)
+ {
+ zavai.log.error("Hook " + name + " does not exist");
+ return false;
+ }
+ string command = script + " status";
int res = zavai.config.run_script_sync(command, out std_out, out std_err);
if (res != 0)
{