Dobby 3.0
Dobby “Docker based Thingy” is a tool for managing and running OCI containers using crun
Loading...
Searching...
No Matches
Dobby.h
1/*
2* If not stated otherwise in this file or this component's LICENSE file the
3* following copyright and licenses apply:
4*
5* Copyright 2016 Sky UK
6*
7* Licensed under the Apache License, Version 2.0 (the "License");
8* you may not use this file except in compliance with the License.
9* You may obtain a copy of the License at
10*
11* http://www.apache.org/licenses/LICENSE-2.0
12*
13* Unless required by applicable law or agreed to in writing, software
14* distributed under the License is distributed on an "AS IS" BASIS,
15* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16* See the License for the specific language governing permissions and
17* limitations under the License.
18*/
19/*
20 * File: Dobby.h
21 *
22 */
23#ifndef DOBBY_H
24#define DOBBY_H
25
26#include "ContainerId.h"
27
28#include <IIpcService.h>
29
30#include <signal.h>
31
32#include <list>
33#include <mutex>
34#include <atomic>
35#include <memory>
36#include <string>
37#include <condition_variable>
38
39class DobbyEnv;
40class DobbyUtils;
41class DobbyIPCUtils;
42class DobbyManager;
43class DobbyWorkQueue;
44class DobbyLogger;
45class IDobbySettings;
46
47// -----------------------------------------------------------------------------
55class Dobby
56{
57public:
58 Dobby(const std::string& dbusAddress,
59 const std::shared_ptr<AI_IPC::IIpcService>& ipcService,
60 const std::shared_ptr<const IDobbySettings>& settings);
61 ~Dobby();
62
63public:
64 void run() const;
65
66public:
67 static void configSignals();
68
69public:
70 enum LogTarget : unsigned { Console = 0x1, SysLog = 0x2, EthanLog = 0x4, Journald = 0x8 };
71 static void setupLogging(unsigned targets = LogTarget::Console);
72
73public:
74 void setDefaultAIDbusAddresses(const std::string& aiPrivateBusAddress,
75 const std::string& aiPublicBusAddress);
76
77private:
78 #define DOBBY_DBUS_METHOD(x) \
79 void x(std::shared_ptr<AI_IPC::IAsyncReplySender> reply)
80
81 DOBBY_DBUS_METHOD(ping);
82 DOBBY_DBUS_METHOD(shutdown);
83 DOBBY_DBUS_METHOD(setLogMethod);
84 DOBBY_DBUS_METHOD(setLogLevel);
85 DOBBY_DBUS_METHOD(setAIDbusAddress);
86
87 DOBBY_DBUS_METHOD(startFromSpec);
88 DOBBY_DBUS_METHOD(startFromBundle);
89 DOBBY_DBUS_METHOD(stop);
90 DOBBY_DBUS_METHOD(pause);
91 DOBBY_DBUS_METHOD(resume);
92 DOBBY_DBUS_METHOD(hibernate);
93 DOBBY_DBUS_METHOD(wakeup);
94 DOBBY_DBUS_METHOD(addMount);
95 DOBBY_DBUS_METHOD(removeMount);
96 DOBBY_DBUS_METHOD(exec);
97 DOBBY_DBUS_METHOD(list);
98 DOBBY_DBUS_METHOD(getState);
99 DOBBY_DBUS_METHOD(getInfo);
100
101#if defined(LEGACY_COMPONENTS) && (AI_BUILD_TYPE == AI_DEBUG)
102 DOBBY_DBUS_METHOD(createBundle);
103 DOBBY_DBUS_METHOD(getSpec);
104#endif //defined(LEGACY_COMPONENTS) && (AI_BUILD_TYPE == AI_DEBUG)
105
106#if (AI_BUILD_TYPE == AI_DEBUG)
107 DOBBY_DBUS_METHOD(getOCIConfig);
108#endif //(AI_BUILD_TYPE == AI_DEBUG)
109
110#if defined(AI_ENABLE_TRACING)
111 DOBBY_DBUS_METHOD(startInProcessTracing);
112 DOBBY_DBUS_METHOD(stopInProcessTracing);
113#endif
114
115 DOBBY_DBUS_METHOD(addAnnotation);
116 DOBBY_DBUS_METHOD(removeAnnotation);
117
118 #undef DOBBY_DBUS_METHOD
119
120private:
121 void initIpcMethods();
122
123#if defined(RDK)
124 void initWatchdog();
125 bool onWatchdogTimer();
126#endif
127
128
129private:
130 void onContainerStarted(int32_t cd, const ContainerId& id);
131 void onContainerStopped(int32_t cd, const ContainerId& id, int status);
132 void onContainerHibernated(int32_t cd, const ContainerId& id);
133 void onContainerAwoken(int32_t cd, const ContainerId& id);
134
135private:
136 void runWorkQueue() const;
137
138private:
139 std::shared_ptr<DobbyEnv> mEnvironment;
140 std::shared_ptr<DobbyUtils> mUtilities;
141 std::shared_ptr<DobbyIPCUtils> mIPCUtilities;
142 std::shared_ptr<DobbyManager> mManager;
143 std::unique_ptr<DobbyWorkQueue> mWorkQueue;
144
145private:
146 const std::shared_ptr<AI_IPC::IIpcService> mIpcService;
147 const std::string mService;
148 const std::string mObjectPath;
149 std::list<std::string> mHandlers;
150
151private:
152 std::atomic<bool> mShutdown;
153
154 int mWatchdogTimerId;
155
156private:
157 static void nullSigChildHandler(int sigNum, siginfo_t *info, void *context);
158
159 static volatile sig_atomic_t mSigTerm;
160 static void sigTermHandler(int sigNum);
161
162private:
163 static void logPrinter(int level, const char *file, const char *func,
164 int line, const char *message);
165 static void logConsolePrinter(int level, const char *file, const char *func,
166 int line, const char *message);
167#if defined(RDK)
168 static void logJournaldPrinter(int level, const char *file, const char *func,
169 int line, const char *message);
170#endif
171
172 static std::atomic<unsigned> mLogTargets;
173 static int mEthanLogPipeFd;
174};
175
176
177#endif // !defined(DOBBY_H)
A wrapper around a std::string, used to add some type definition to to an id and also to sanity check...
Definition ContainerId.h:41
Basic class used to store the stb environment.
Definition DobbyEnv.h:46
Utility methods for IPC in Dobby.
Definition DobbyIPCUtils.h:44
Definition DobbyLogger.h:41
The main object which starts / stops / manages the containers.
Definition DobbyManager.h:77
Utility methods for hooks and the general containiser daemon.
Definition DobbyUtils.h:43
Definition DobbyWorkQueue.h:37
The root Dobby object, runs the dbus loop.
Definition Dobby.h:56
static std::atomic< unsigned > mLogTargets
The target for logging, can be dynamically changed via dbus.
Definition Dobby.h:172
static void setupLogging(unsigned targets=LogTarget::Console)
Static method must be called early in the startup before object is instantiated.
Definition Dobby.cpp:479
void onContainerStopped(int32_t cd, const ContainerId &id, int status)
Called by the DobbyManager code when a container has stopped.
Definition Dobby.cpp:2201
static void configSignals()
Utility function that MUST be called at startup from the main thread before any other threads are spa...
Definition Dobby.cpp:213
static void sigTermHandler(int sigNum)
Signal handler for SIGTERM.
Definition Dobby.cpp:181
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.
Definition Dobby.cpp:414
void runWorkQueue() const
Runs the Dobby work queue to handle API calls.
Definition Dobby.cpp:531
static int mEthanLogPipeFd
Definition Dobby.h:173
void setDefaultAIDbusAddresses(const std::string &aiPrivateBusAddress, const std::string &aiPublicBusAddress)
Debugging function for manually setting the AI dbus addresses.
Definition Dobby.cpp:605
void onContainerAwoken(int32_t cd, const ContainerId &id)
Called by the DobbyManager code when a container returns back from hibernated.
Definition Dobby.cpp:2268
void initIpcMethods()
Installs handlers for all the dbus/ipc methods.
Definition Dobby.cpp:623
void onContainerStarted(int32_t cd, const ContainerId &id)
Called by the DobbyManager code when a container has started.
Definition Dobby.cpp:2168
static void nullSigChildHandler(int sigNum, siginfo_t *info, void *context)
Signal handler that does nothing.
Definition Dobby.cpp:196
void onContainerHibernated(int32_t cd, const ContainerId &id)
Called by the DobbyManager code when a container gets hibernated.
Definition Dobby.cpp:2242
static void logConsolePrinter(int level, const char *file, const char *func, int line, const char *message)
Writes logging output to the console.
Definition Dobby.cpp:272
void run() const
Issues a 'ready' signal over dbus and then blocks until either a shutdown request is received or SIGT...
Definition Dobby.cpp:559
Interface provided to the library at startup, contains the configuration options for Dobby.
Definition IDobbySettings.h:50