add create-server
This commit is contained in:
parent
84c252c965
commit
d9f6897de0
@ -13,7 +13,7 @@
|
|||||||
#include <boost/filesystem.hpp>
|
#include <boost/filesystem.hpp>
|
||||||
#include <boost/algorithm/string.hpp>
|
#include <boost/algorithm/string.hpp>
|
||||||
#include <execution>
|
#include <execution>
|
||||||
|
#include <filesystem>
|
||||||
namespace fs = boost::filesystem;
|
namespace fs = boost::filesystem;
|
||||||
|
|
||||||
namespace dropshell {
|
namespace dropshell {
|
||||||
@ -146,4 +146,44 @@ void show_server_details(const std::string& server_name) {
|
|||||||
} // end of list services
|
} // end of list services
|
||||||
} // end of show_server_details
|
} // end of show_server_details
|
||||||
|
|
||||||
|
void create_server(const std::string &server_name)
|
||||||
|
{
|
||||||
|
// 1. check if server name already exists
|
||||||
|
std::string server_existing_dir = get_local_server_path(server_name);
|
||||||
|
if (!server_existing_dir.empty()) {
|
||||||
|
std::cerr << "Error: Server name already exists: " << server_name << std::endl;
|
||||||
|
std::cerr << "Current server path: " << server_existing_dir << std::endl;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. create a new directory in the user config directory
|
||||||
|
std::string config_dir = get_local_config_path(0);
|
||||||
|
std::string server_dir = config_dir + "/" + server_name;
|
||||||
|
fs::create_directory(server_dir);
|
||||||
|
|
||||||
|
// 3. create a template server.env file in the server directory
|
||||||
|
std::string user = getenv("USER");
|
||||||
|
std::string server_env_path = server_dir + "/server.env";
|
||||||
|
std::ofstream server_env_file(server_env_path);
|
||||||
|
server_env_file << "SSH_HOST=" << server_name << std::endl;
|
||||||
|
server_env_file << "SSH_USER=" << user << std::endl;
|
||||||
|
server_env_file << "SSH_PORT=" << 22 << std::endl;
|
||||||
|
server_env_file << std::endl;
|
||||||
|
server_env_file << "DROPSHELL_PATH=/home/"+user+"/.dropshell" << std::endl;
|
||||||
|
server_env_file.close();
|
||||||
|
|
||||||
|
// 4. add dropshell-agent service to server
|
||||||
|
std::string service_dir = server_dir + "/dropshell-agent";
|
||||||
|
fs::create_directory(service_dir);
|
||||||
|
std::string service_env_path = service_dir + "/service.env";
|
||||||
|
std::filesystem::copy(get_local_system_templates_path() + "/dropshell-agent/service.env", service_env_path);
|
||||||
|
|
||||||
|
std::cout << "Server created successfully: " << server_name << std::endl;
|
||||||
|
std::cout << "Please edit the server.env file to configure the server, it is located at: "<<std::endl;
|
||||||
|
std::cout << " " << server_env_path << std::endl;
|
||||||
|
std::cout << "Then run 'dropshell install " << server_name << " dropshell-agent' to install the agent" << std::endl;
|
||||||
|
std::cout << std::endl;
|
||||||
|
std::cout << "You can then start managing your server with DropShell" << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace dropshell
|
} // namespace dropshell
|
@ -20,6 +20,8 @@ std::vector<ServerInfo> get_configured_servers();
|
|||||||
void list_servers();
|
void list_servers();
|
||||||
void show_server_details(const std::string& server_name);
|
void show_server_details(const std::string& server_name);
|
||||||
|
|
||||||
|
void create_server(const std::string& server_name);
|
||||||
|
|
||||||
} // namespace dropshell
|
} // namespace dropshell
|
||||||
|
|
||||||
#endif // SERVERS_HPP
|
#endif // SERVERS_HPP
|
||||||
|
Loading…
x
Reference in New Issue
Block a user