More instructions

This commit is contained in:
Your Name
2025-04-25 23:29:50 +12:00
parent fb46dffdaf
commit 3c99ad1503
6 changed files with 103 additions and 25 deletions

View File

@ -230,6 +230,10 @@ bool service_runner::uninstall() {
return true;
}
// ------------------------------------------------------------------------------------------------
// Run a command on the service.
// ------------------------------------------------------------------------------------------------
bool service_runner::run_command(const std::string& command) {
if (!m_server_env) {
std::cerr << "Error: Server service not initialized" << std::endl;
@ -240,6 +244,13 @@ bool service_runner::run_command(const std::string& command) {
std::cerr << "Error: Template '" << m_service_info.template_name << "' not found" << std::endl;
return false;
}
// don't need a script for edit!
if (command == "edit") {
edit_service_config();
return true;
}
if (!template_command_exists(m_service_info.template_name, command)) {
std::cout << "No command script for " << m_service_info.template_name << " : " << command << std::endl;
return true; // nothing to run.
@ -280,6 +291,11 @@ bool service_runner::run_command(const std::string& command) {
return execute_ssh_command(run_cmd, "Command returned error code: " + script_path);
}
// ------------------------------------------------------------------------------------------------
// Backup the service.
// ------------------------------------------------------------------------------------------------
bool service_runner::backup() {
maketitle("Backing up " + m_service_info.service_name + " (" + m_service_info.template_name + ") on " + m_server_name);
@ -514,6 +530,33 @@ void interactive_ssh(const std::string & server_name, const std::string & comman
exit(EXIT_FAILURE);
}
void edit_server(const std::string &server_name)
{
std::string serverpath = get_local_server_path(server_name);
if (serverpath.empty()) {
std::cerr << "Error: Server not found: " << server_name << std::endl;
return;
}
std::ostringstream aftertext;
aftertext << "If you have changed DROPSHELL_DIR, you should manually move the files to the new location NOW.\n"
<< "You can ssh in to the remote server with: dropshell ssh "<<server_name<<"\n"
<< "Once moved, reinstall all services with: dropshell install " << server_name;
std::string config_file = serverpath + "/server.env";
edit_file(config_file, aftertext.str());
}
void edit_file(const std::string &file_path, const std::string & aftertext)
{
std::string cmd = "nano -w "+file_path+" ; echo \""+aftertext+"\"";
execlp("bash","bash","-c",cmd.c_str(), nullptr);
// If exec returns, it means there was an error
perror("ssh execution failed");
exit(EXIT_FAILURE);
}
void service_runner::interactive_ssh_service()
{
std::set<std::string> used_commands = get_used_commands(m_server_name, m_service_info.service_name);
@ -526,6 +569,17 @@ void service_runner::interactive_ssh_service()
interactive_ssh(m_server_name, "/bin/bash -c '"+command+"'");
}
void service_runner::edit_service_config()
{
std::string config_file = get_local_service_env_path(m_server_name, m_service_info.service_name);
if (!fs::exists(config_file)) {
std::cerr << "Error: Service config file not found: " << config_file << std::endl;
return;
}
std::string aftertext = "To apply your changes, run:\n dropshell install " + m_server_name + " " + m_service_info.service_name;
edit_file(config_file, aftertext);
}
} // namespace dropshell