.
This commit is contained in:
parent
395c9deb45
commit
080e384560
@ -42,8 +42,8 @@ bool service_runner::install() {
|
||||
if (!mServerEnv.is_valid()) return false; // should never hit this.
|
||||
|
||||
// Check if template exists
|
||||
template_info tinfo;
|
||||
if (!get_template_info(mServiceInfo.template_name, tinfo))
|
||||
template_info tinfo = gTemplateManager().get_template_info(mServiceInfo.template_name);
|
||||
if (!tinfo.is_set())
|
||||
return false;
|
||||
|
||||
// Create service directory
|
||||
@ -65,9 +65,9 @@ bool service_runner::install() {
|
||||
|
||||
// Copy template files
|
||||
{
|
||||
std::cout << "Copying: [LOCAL] " << tinfo.local_template_path << std::endl << std::string(8,' ')<<"[REMOTE] " << remotepath::service_template(mServer, mService) << "/" << std::endl;
|
||||
std::cout << "Copying: [LOCAL] " << tinfo.local_template_path() << std::endl << std::string(8,' ')<<"[REMOTE] " << remotepath::service_template(mServer, mService) << "/" << std::endl;
|
||||
std::string rsync_cmd = "rsync --delete -zrpc -e 'ssh -p " + mServerEnv.get_SSH_PORT() + "' " +
|
||||
quote(tinfo.local_template_path + "/") + " "+
|
||||
quote(tinfo.local_template_path().string()+"/") + " "+
|
||||
mServerEnv.get_SSH_USER() + "@" + mServerEnv.get_SSH_HOST() + ":" +
|
||||
quote(remotepath::service_template(mServer, mService)+"/");
|
||||
//std::cout << std::endl << rsync_cmd << std::endl << std::endl;
|
||||
@ -195,8 +195,8 @@ bool service_runner::run_command(const std::string& command, std::vector<std::st
|
||||
std::cerr << "Error: Server service not initialized" << std::endl;
|
||||
return false;
|
||||
}
|
||||
template_info tinfo;
|
||||
if (!get_template_info(mServiceInfo.template_name, tinfo)) {
|
||||
template_info tinfo = gTemplateManager().get_template_info(mServiceInfo.template_name);
|
||||
if (!tinfo.is_set()) {
|
||||
std::cerr << "Error: Template '" << mServiceInfo.template_name << "' not found" << std::endl;
|
||||
return false;
|
||||
}
|
||||
@ -207,7 +207,7 @@ bool service_runner::run_command(const std::string& command, std::vector<std::st
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!template_command_exists(mServiceInfo.template_name, command)) {
|
||||
if (!gTemplateManager().template_command_exists(mServiceInfo.template_name, command)) {
|
||||
std::cout << "No command script for " << mServiceInfo.template_name << " : " << command << std::endl;
|
||||
return true; // nothing to run.
|
||||
}
|
||||
@ -268,7 +268,7 @@ std::map<std::string, ServiceStatus> service_runner::get_all_services_status(std
|
||||
std::string command = "_allservicesstatus";
|
||||
std::string service_name = "dropshell-agent";
|
||||
|
||||
if (!template_command_exists(service_name, command))
|
||||
if (!gTemplateManager().template_command_exists(service_name, command))
|
||||
{
|
||||
std::cerr << "Error: " << service_name << " does not contain the " << command << " script" << std::endl;
|
||||
return status;
|
||||
@ -604,7 +604,7 @@ bool service_runner::backup(bool silent) {
|
||||
|
||||
const std::string command = "backup";
|
||||
|
||||
if (!template_command_exists(service_info.template_name, command)) {
|
||||
if (!gTemplateManager().template_command_exists(service_info.template_name, command)) {
|
||||
std::cout << "No backup script for " << service_info.template_name << std::endl;
|
||||
return true; // nothing to back up.
|
||||
}
|
||||
|
@ -37,18 +37,9 @@
|
||||
return std::filesystem::exists(mLocalPath / template_name);
|
||||
}
|
||||
|
||||
std::string template_source_local::template_command_filename(const std::string& template_name, const std::string& command) {
|
||||
std::vector<std::string> commands = {
|
||||
command,
|
||||
command + ".sh"
|
||||
};
|
||||
|
||||
for (const auto& cmd : commands) {
|
||||
std::filesystem::path path = mLocalPath / template_name / cmd;
|
||||
if (std::filesystem::exists(path))
|
||||
return cmd;
|
||||
}
|
||||
return "";
|
||||
bool template_source_local::template_command_exists(const std::string& template_name, const std::string& command) {
|
||||
std::filesystem::path path = mLocalPath / template_name / (command+".sh");
|
||||
return std::filesystem::exists(path);
|
||||
}
|
||||
|
||||
template_info template_source_local::get_template_info(const std::string& template_name) {
|
||||
|
@ -36,7 +36,7 @@ class template_source_interface {
|
||||
virtual std::set<std::string> get_template_list() = 0;
|
||||
virtual bool has_template(const std::string& template_name) = 0;
|
||||
virtual template_info get_template_info(const std::string& template_name) = 0;
|
||||
virtual std::string template_command_filename(const std::string& template_name,const std::string& command) = 0;
|
||||
virtual bool template_command_exists(const std::string& template_name,const std::string& command) = 0;
|
||||
};
|
||||
|
||||
class template_source_registry : public template_source_interface {
|
||||
@ -48,7 +48,7 @@ class template_source_registry : public template_source_interface {
|
||||
std::set<std::string> get_template_list();
|
||||
bool has_template(const std::string& template_name);
|
||||
template_info get_template_info(const std::string& template_name);
|
||||
std::string template_command_filename(const std::string& template_name,const std::string& command);
|
||||
bool template_command_exists(const std::string& template_name,const std::string& command);
|
||||
private:
|
||||
std::filesystem::path get_cache_dir();
|
||||
private:
|
||||
@ -63,7 +63,7 @@ class template_source_local : public template_source_interface {
|
||||
std::set<std::string> get_template_list();
|
||||
bool has_template(const std::string& template_name);
|
||||
template_info get_template_info(const std::string& template_name);
|
||||
std::string template_command_filename(const std::string& template_name,const std::string& command);
|
||||
bool template_command_exists(const std::string& template_name,const std::string& command);
|
||||
private:
|
||||
std::filesystem::path mLocalPath;
|
||||
};
|
||||
@ -77,7 +77,7 @@ class template_manager {
|
||||
bool has_template(const std::string& template_name);
|
||||
template_info get_template_info(const std::string& template_name);
|
||||
|
||||
std::string template_command_filename(const std::string& template_name,const std::string& command);
|
||||
bool template_command_exists(const std::string& template_name,const std::string& command);
|
||||
void create_template(const std::string& template_name);
|
||||
bool test_template(const std::string& template_path);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user