Dobby  3.0
Dobby “Docker based Thingy” is a tool for managing and running OCI containers using crun
Public Types | Public Member Functions | Static Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | Static Private Attributes | List of all members
Dobby Class Reference

The root Dobby object, runs the dbus loop. More...

#include <Dobby.h>

Public Types

enum  LogTarget : unsigned { Console = 0x1 , SysLog = 0x2 , EthanLog = 0x4 , Journald = 0x8 }
 

Public Member Functions

 Dobby (const std::string &dbusAddress, const std::shared_ptr< AI_IPC::IIpcService > &ipcService, const std::shared_ptr< const IDobbySettings > &settings)
 
void run () const
 Issues a 'ready' signal over dbus and then blocks until either a shutdown request is received or SIGTERM.
 
void setDefaultAIDbusAddresses (const std::string &aiPrivateBusAddress, const std::string &aiPublicBusAddress)
 Debugging function for manually setting the AI dbus addresses. More...
 

Static Public Member Functions

static void configSignals ()
 Utility function that MUST be called at startup from the main thread before any other threads are spawned. More...
 
static void setupLogging (unsigned targets=LogTarget::Console)
 Static method must be called early in the startup before object is instantiated. More...
 

Private Member Functions

 DOBBY_DBUS_METHOD (ping)
 
 DOBBY_DBUS_METHOD (shutdown)
 
 DOBBY_DBUS_METHOD (setLogMethod)
 
 DOBBY_DBUS_METHOD (setLogLevel)
 
 DOBBY_DBUS_METHOD (setAIDbusAddress)
 
 DOBBY_DBUS_METHOD (startFromSpec)
 
 DOBBY_DBUS_METHOD (startFromBundle)
 
 DOBBY_DBUS_METHOD (stop)
 
 DOBBY_DBUS_METHOD (pause)
 
 DOBBY_DBUS_METHOD (resume)
 
 DOBBY_DBUS_METHOD (hibernate)
 
 DOBBY_DBUS_METHOD (wakeup)
 
 DOBBY_DBUS_METHOD (addMount)
 
 DOBBY_DBUS_METHOD (removeMount)
 
 DOBBY_DBUS_METHOD (exec)
 
 DOBBY_DBUS_METHOD (list)
 
 DOBBY_DBUS_METHOD (getState)
 
 DOBBY_DBUS_METHOD (getInfo)
 
 DOBBY_DBUS_METHOD (getOCIConfig)
 
void initIpcMethods ()
 Installs handlers for all the dbus/ipc methods.
 
void onContainerStarted (int32_t cd, const ContainerId &id)
 Called by the DobbyManager code when a container has started. More...
 
void onContainerStopped (int32_t cd, const ContainerId &id, int status)
 Called by the DobbyManager code when a container has stopped. More...
 
void onContainerHibernated (int32_t cd, const ContainerId &id)
 Called by the DobbyManager code when a container gets hibernated. More...
 
void onContainerAwoken (int32_t cd, const ContainerId &id)
 Called by the DobbyManager code when a container returns back from hibernated. More...
 
void runWorkQueue () const
 Runs the Dobby work queue to handle API calls.
 

Static Private Member Functions

static void nullSigChildHandler (int sigNum, siginfo_t *info, void *context)
 Signal handler that does nothing. More...
 
static void sigTermHandler (int sigNum)
 Signal handler for SIGTERM.
 
static void logPrinter (int level, const char *file, const char *func, int line, const char *message)
 Logging callback, called every time a log message needs to be emitted. More...
 
static void logConsolePrinter (int level, const char *file, const char *func, int line, const char *message)
 Writes logging output to the console. More...
 

Private Attributes

std::shared_ptr< DobbyEnvmEnvironment
 
std::shared_ptr< DobbyUtilsmUtilities
 
std::shared_ptr< DobbyIPCUtilsmIPCUtilities
 
std::shared_ptr< DobbyManagermManager
 
std::unique_ptr< DobbyWorkQueuemWorkQueue
 
const std::shared_ptr< AI_IPC::IIpcServicemIpcService
 
const std::string mService
 
const std::string mObjectPath
 
std::list< std::string > mHandlers
 
std::atomic< bool > mShutdown
 
int mWatchdogTimerId
 

Static Private Attributes

static volatile sig_atomic_t mSigTerm = 0
 
static std::atomic< unsigned > mLogTargets
 The target for logging, can be dynamically changed via dbus.
 
static int mEthanLogPipeFd = -1
 

Detailed Description

The root Dobby object, runs the dbus loop.

Member Function Documentation

◆ configSignals()

void Dobby::configSignals ( )
static

Utility function that MUST be called at startup from the main thread before any other threads are spawned.

This is needed to fix a bunch of quirks relating to how signals are handled, in particular the SIGCHLD signal.

◆ logConsolePrinter()

void Dobby::logConsolePrinter ( int  level,
const char *  file,
const char *  func,
int  line,
const char *  message 
)
staticprivate

Writes logging output to the console.

This duplicates code in the Logging component, but unfortunately we can't use the function there without messing up the API for all other things that use it.

◆ logPrinter()

void Dobby::logPrinter ( int  level,
const char *  file,
const char *  func,
int  line,
const char *  message 
)
staticprivate

Logging callback, called every time a log message needs to be emitted.

Depending on the log method, this will either send the message to syslog or the ethanlog library.

Note that this function is called after any processing in the Logger component, meaning that you can still print log messages on the console by using the AI_LOG_CHANNELS env var.

◆ nullSigChildHandler()

void Dobby::nullSigChildHandler ( int  sigNum,
siginfo_t *  info,
void *  context 
)
staticprivate

Signal handler that does nothing.

This is needed to ensure SIGCHLD signals are actually delivered and detected by sigwaitinfo

◆ onContainerAwoken()

void Dobby::onContainerAwoken ( int32_t  cd,
const ContainerId id 
)
private

Called by the DobbyManager code when a container returns back from hibernated.

Parameters
[in]cdThe container unique descriptor.
[in]idThe string id / name of the container.

◆ onContainerHibernated()

void Dobby::onContainerHibernated ( int32_t  cd,
const ContainerId id 
)
private

Called by the DobbyManager code when a container gets hibernated.

Parameters
[in]cdThe container unique descriptor.
[in]idThe string id / name of the container.

◆ onContainerStarted()

void Dobby::onContainerStarted ( int32_t  cd,
const ContainerId id 
)
private

Called by the DobbyManager code when a container has started.

This is typically called from DobbyManager in response to a DobbyManager::onPostStartHook, so just beware it's recursive from the dbus thread POV.

Parameters
[in]cdThe container unique descriptor.
[in]idThe string id / name of the container.

◆ onContainerStopped()

void Dobby::onContainerStopped ( int32_t  cd,
const ContainerId id,
int  status 
)
private

Called by the DobbyManager code when a container has stopped.

This is typically called from an internal thread in the DobbyManager so be careful of any threading issues.

Parameters
[in]cdThe container unique descriptor.
[in]idThe string id / name of the container.
[in]statusThe status result of the container's runc process.

◆ setDefaultAIDbusAddresses()

void Dobby::setDefaultAIDbusAddresses ( const std::string &  aiPrivateBusAddress,
const std::string &  aiPublicBusAddress 
)

Debugging function for manually setting the AI dbus addresses.

Parameters
[in]aiPrivateBusAddressThe AI private dbus address
[in]aiPublicBusAddressThe AI public dbus address

◆ setupLogging()

void Dobby::setupLogging ( unsigned  targets = LogTarget::Console)
static

Static method must be called early in the startup before object is instantiated.

If the function detects the ETHAN_LOGGING_PIPE env var then it sets the default logging method to 'ethan log', otherwise it defaults to syslog.

Member Data Documentation

◆ mEthanLogPipeFd

int Dobby::mEthanLogPipeFd = -1
staticprivate

The fd of the ethan logging pipe, starts off pointing to /dev/null but can changed dynamically via dbus


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