22 #include "softwarecontainer-common.h" 23 #include "createdir.h" 26 #include <lxc/lxccontainer.h> 29 ContainerUtilityInterface::ContainerUtilityInterface(std::shared_ptr<Config> config)
30 : m_config(std::move(config))
36 char **containerNames =
nullptr;
37 struct lxc_container **containerList =
nullptr;
39 const char *basePath = lxc_get_global_config_item(
"lxc.lxcpath");
40 auto num = list_all_containers(basePath, &containerNames, &containerList);
45 delete containerNames;
47 }
else if (-1 == num) {
48 log_error() <<
"An error is occurred while trying to get deprecated container list";
52 log_warning() << num <<
" unused deprecated containers found";
53 for (
auto i = 0; i < num; i++) {
54 struct lxc_container *container = containerList[i];
55 log_debug() <<
"Deprecated container named " << containerNames[i] <<
" will be deleted";
57 if (container->is_running(container)) {
58 bool success = container->stop(container);
60 std::string errorMsg =
"Unable to stop deprecated container " +
61 std::string(containerNames[i]);
66 bool success = container->destroy(container);
68 std::string errorMsg =
"Unable to destroy deprecated container " +
69 std::string(containerNames[i]);
73 log_debug() <<
"Deprecated container " << containerNames[i] <<
" is successfully destroyed";
75 delete containerNames[i];
78 delete containerNames;
83 const std::string rootDir = m_config->getStringValue(
"SoftwareContainer",
"shared-mounts-dir");
85 log_debug() <<
"Container root " << rootDir <<
" does not exist, trying to create";
86 std::unique_ptr<CreateDir> createDirInstance(
new CreateDir());
87 if(!createDirInstance->createDirectory(rootDir)) {
88 std::string message =
"Failed to create container root directory";
89 log_error() << message;
93 m_createDirList.push_back(std::move(createDirInstance));
void removeOldContainers(void)
This method cleans unused old containers before agent starts up.
The CreateDir class is responsible for creating new directories and removing them when it is necessar...
An error occured in ContainerUtilityInterface.
Contains the softwarecontainer::ContainerUtilityAbstractInterface class.
bool isDirectory(const std::string &path)
isDirectory Check if path is a directory
void checkWorkspace(void)
Check that the workspace exists.
Developers guide to adding a config item: