softwarecontainer
0.18.0-739e8d7 2017-05-04
|
The Container class is an abstraction of the specific containment technology used. More...
#include <container.h>
Public Types | |
typedef std::function< int()> | ExecFunction |
Public Member Functions | |
Container (const std::string id, const std::string &configFile, const std::string &containerRoot, bool writeBufferEnabled=false, int shutdownTimeout=1) | |
Constructor. More... | |
bool | create () |
create Creates a new lxc_container and creates it with all the initialization. More... | |
bool | start (pid_t *pid) |
Start the container. More... | |
bool | setCgroupItem (std::string subsys, std::string value) |
bool | execute (const std::string &commandLine, pid_t *pid, const EnvironmentVariables &variables, const std::string &workingDirectory="/", int stdin=-1, int stdout=1, int stderr=2) |
Start a process from the given command line, with an environment consisting of the variables previously set by the gateways, plus the ones passed as parameters here. More... | |
bool | execute (ExecFunction function, pid_t *pid, const EnvironmentVariables &variables=EnvironmentVariables(), int stdin=-1, int stdout=1, int stderr=2) |
Executes a commandline. More... | |
bool | executeSync (ExecFunction function, pid_t *pid, const EnvironmentVariables &variables=EnvironmentVariables(), int stdin=-1, int stdout=1, int stderr=2) |
synchronous version of execute More... | |
bool | bindMountInContainer (const std::string &pathInHost, const std::string &pathInContainer, bool readOnly=true) |
Tries to bind mount a path from host to container. More... | |
bool | mountDevice (const std::string &pathInHost) |
bool | destroy () |
Calls shutdown, and then destroys the container. More... | |
bool | destroy (unsigned int timeout) |
bool | shutdown () |
Calls shutdown on the lxc container. More... | |
bool | shutdown (unsigned int timeout) |
bool | suspend () |
bool | resume () |
bool | stop () |
Calls stop on the lxc container(force stop) More... | |
bool | waitForState (LXCContainerState state, int timeout=20) |
bool | ensureContainerRunning () |
bool | initialize () |
Setup the container for startup. More... | |
std::string | toString () |
const char * | id () const |
std::string | gatewaysDirInContainer () const |
std::string | gatewaysDir () const |
bool | setEnvironmentVariable (const std::string &var, const std::string &val) |
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... | |
The Container class is an abstraction of the specific containment technology used.
The Container class is meant to be an abstraction of the containment technology, so that SoftwareContainer can view it as a generic concept that implements the specifics behind the conceptual phases of 'Pereload', 'Launch', and 'Shutdown'.
Definition at line 42 of file container.h.
softwarecontainer::Container::Container | ( | const std::string | id, |
const std::string & | configFile, | ||
const std::string & | containerRoot, | ||
bool | writeBufferEnabled = false , |
||
int | shutdownTimeout = 1 |
||
) |
Constructor.
name | Name of the container |
configFile | Path to the configuration file (including the file name) |
containerRoot | A path to the root of the container, i.e. the base path to e.g. the configurations and application root |
writeBufferEnabled | Enable RAM write buffers on top of rootfs |
shutdownTimeout | Timeout for shutdown of container. |
Definition at line 75 of file container.cpp.
References destroy(), and shutdown().
|
virtual |
create Creates a new lxc_container and creates it with all the initialization.
Implements softwarecontainer::ContainerAbstractInterface.
Definition at line 145 of file container.cpp.
References softwarecontainer::FileToolkitWithUndo::overlayMount().
|
virtual |
Start the container.
Implements softwarecontainer::ContainerAbstractInterface.
Definition at line 265 of file container.cpp.
|
virtual |
Start a process from the given command line, with an environment consisting of the variables previously set by the gateways, plus the ones passed as parameters here.
Implements softwarecontainer::Executable.
Definition at line 429 of file container.cpp.
Referenced by executeSync().
|
virtual |
Executes a commandline.
Implements softwarecontainer::Executable.
Definition at line 349 of file container.cpp.
bool softwarecontainer::Container::executeSync | ( | ExecFunction | function, |
pid_t * | pid, | ||
const EnvironmentVariables & | variables = EnvironmentVariables() , |
||
int | stdin = -1 , |
||
int | stdout = 1 , |
||
int | stderr = 2 |
||
) |
synchronous version of execute
Definition at line 335 of file container.cpp.
References execute(), and softwarecontainer::waitForProcessTermination().
Referenced by bindMountInContainer().
|
virtual |
Tries to bind mount a path from host to container.
Any missing parent paths will be created.
pathInHost | The path on the host that shall be bind mounted into the container |
pathInContainer | Where to mount the path in the container. |
readonly | Sets if the mount should be read only or read write |
Implements softwarecontainer::ContainerAbstractInterface.
Definition at line 571 of file container.cpp.
References softwarecontainer::FileToolkitWithUndo::bindMount(), executeSync(), softwarecontainer::existsInFileSystem(), softwarecontainer::isDirectory(), softwarecontainer::FileToolkitWithUndo::m_cleanupHandlers, softwarecontainer::FileToolkitWithUndo::m_createDirList, and softwarecontainer::FileToolkitWithUndo::pathInList().
|
virtual |
Calls shutdown, and then destroys the container.
Implements softwarecontainer::ContainerAbstractInterface.
Definition at line 530 of file container.cpp.
References shutdown().
Referenced by Container().
|
virtual |
Calls shutdown on the lxc container.
Implements softwarecontainer::ContainerAbstractInterface.
Definition at line 497 of file container.cpp.
References stop().
Referenced by Container(), and destroy().
|
virtual |
Calls stop on the lxc container(force stop)
Implements softwarecontainer::ContainerAbstractInterface.
Definition at line 477 of file container.cpp.
Referenced by shutdown().
|
virtual |
Setup the container for startup.
Setup the container so directories are available for later use when setApplication is called.
Implements softwarecontainer::ContainerAbstractInterface.
Definition at line 109 of file container.cpp.
References softwarecontainer::FileToolkitWithUndo::createSharedMountPoint(), and softwarecontainer::FileToolkitWithUndo::m_createDirList.