softwarecontainer  0.18.0-739e8d7 2017-05-04
softwarecontainer::ContainerUtilityInterface Class Reference
Inheritance diagram for softwarecontainer::ContainerUtilityInterface:
[legend]
Collaboration diagram for softwarecontainer::ContainerUtilityInterface:
[legend]

Public Member Functions

 ContainerUtilityInterface (std::shared_ptr< Config > config)
 
void removeOldContainers (void)
 This method cleans unused old containers before agent starts up. More...
 
void checkWorkspace (void)
 Check that the workspace exists. More...
 

Private Member Functions

bool bindMount (const std::string &src, const std::string &dst, const std::string &tmpContainerRoot, bool readOnly, bool writeBufferEnabled=false)
 bindMount Bind mount a src directory to another position dst. More...
 
bool tmpfsMount (const std::string dst, const int maxSize)
 tmpfsMount Mount a tmpfs in the dst path and limit size of the tmpfs to maxSize More...
 
bool writeToFile (const std::string &path, const std::string &content)
 
void markFileForDeletion (const std::string &path)
 
bool overlayMount (const std::string &lower, const std::string &upper, const std::string &work, const std::string &dst)
 overlayMount Mount a directory with an overlay on top of it. More...
 
bool syncOverlayMount (const std::string &lower, const std::string &upper)
 syncOverlayMount Copy the directory structure from upper layer to the lower layer More...
 
bool createSharedMountPoint (const std::string &path)
 createSharedMountPoint Make the mount point shared, ie new mount points created in one bind mount will also be created in the other mount point. More...
 
bool pathInList (const std::string path)
 checks whether given path is already added to clean up handlers or not More...
 

Private Attributes

std::vector< std::unique_ptr< CleanUpHandler > > m_cleanupHandlers
 m_cleanupHandlers A vector of cleanupHandlers added during the lifetime of the FileToolKitWithUndo that will be run from the destructor. More...
 
std::vector< std::unique_ptr< CreateDir > > m_createDirList
 m_createDirList A vector of CreateDir classes. More...
 

Detailed Description

Definition at line 68 of file containerutilityinterface.h.

Member Function Documentation

void softwarecontainer::ContainerUtilityInterface::removeOldContainers ( void  )

This method cleans unused old containers before agent starts up.

Definition at line 34 of file containerutilityinterface.cpp.

35 {
36  char **containerNames = nullptr;
37  struct lxc_container **containerList = nullptr;
38 
39  const char *basePath = lxc_get_global_config_item("lxc.lxcpath");
40  auto num = list_all_containers(basePath, &containerNames, &containerList);
41 
42  if (0 == num) {
43  // there are no container residue. No need to run more.
44  delete containerList;
45  delete containerNames;
46  return;
47  } else if (-1 == num) {
48  log_error() << "An error is occurred while trying to get deprecated container list";
49  throw ContainerUtilityInterfaceError("An error is occurred while trying to get container list");
50  }
51 
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";
56 
57  if (container->is_running(container)) {
58  bool success = container->stop(container);
59  if (!success) {
60  std::string errorMsg = "Unable to stop deprecated container " +
61  std::string(containerNames[i]);
62  throw ContainerUtilityInterfaceError(errorMsg);
63  }
64  }
65 
66  bool success = container->destroy(container);
67  if (!success) {
68  std::string errorMsg = "Unable to destroy deprecated container " +
69  std::string(containerNames[i]);
70  throw ContainerUtilityInterfaceError(errorMsg);
71  }
72 
73  log_debug() << "Deprecated container " << containerNames[i] << " is successfully destroyed";
74  delete container;
75  delete containerNames[i];
76  }
77  delete containerList;
78  delete containerNames;
79 }
void softwarecontainer::ContainerUtilityInterface::checkWorkspace ( void  )

Check that the workspace exists.

Definition at line 81 of file containerutilityinterface.cpp.

References softwarecontainer::isDirectory().

82 {
83  const std::string rootDir = m_config->getStringValue("SoftwareContainer", "shared-mounts-dir");
84  if (!isDirectory(rootDir)) {
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;
90  throw SoftwareContainerError(message);
91  }
92 
93  m_createDirList.push_back(std::move(createDirInstance));
94  }
95 }
std::vector< std::unique_ptr< CreateDir > > m_createDirList
m_createDirList A vector of CreateDir classes.
bool isDirectory(const std::string &path)
isDirectory Check if path is a directory

Here is the call graph for this function:


The documentation for this class was generated from the following files: