 |
SWC-DB
v0.5.12 C++ documentations
SWC-DB© (Super Wide Column Database) - High Performance Scalable Database (https://github.com/kashirin-alex/swc-db)
|
Go to the documentation of this file.
14 #if defined(SWC_PATH_ETC)
15 #define USE_SWC_PATH_ETC(_) SWC_PATH_ETC
17 #define USE_SWC_PATH_ETC(_default_) _default_
20 #if defined(SWC_PATH_LOG)
21 #define USE_SWC_PATH_LOG(_) SWC_PATH_LOG
23 #define USE_SWC_PATH_LOG(_default_) _default_
26 #if defined(SWC_PATH_RUN)
27 #define USE_SWC_PATH_RUN(_) SWC_PATH_RUN
29 #define USE_SWC_PATH_RUN(_default_) _default_
34 namespace SWC {
namespace Config {
55 auto path = std::filesystem::read_symlink(
"/proc/self/exe", ec);
57 std::cerr <<
"Problem reading file='/proc/self/exe' ";
59 std::cerr << std::endl;
65 ? path.parent_path() : path).parent_path().string();
79 auto verbose = get<Property::Value_bool_g>(
"verbose");
80 if(verbose->get() &&
get_bool(
"quiet")) {
90 auto loglevel = get<Property::Value_enum_g>(
"swc.logging.level");
93 }
else if(loglevel->get() == -1) {
95 <<
"unknown logging level: "<< loglevel->to_string();
102 SWC_SHOULD_NOT_INLINE
106 (
"help,h",
"Show this help message and exit")
107 (
"help-config",
"Show help message for config properties")
108 (
"version,v",
"Show version information and exit")
111 (
"debug",
boo(
false)->
zero_token(),
"Shortcut to --swc.logging.level debug")
113 (
"daemon ",
boo()->
zero_token(),
"Start process in background mode")
117 "Path of configuration files")
119 (
"swc.cfg",
str(
"swc.cfg"),
"Main configuration file")
120 (
"swc.cfg.dyn",
strs(),
"Main dynamic configuration file")
122 (
"swc.logging.level,l",
129 "Logging level: debug|info|notice|warn|error|crit|alert|fatal")
142 SWC_SHOULD_NOT_INLINE
161 if (
has(
"help-config")) {
166 if (
has(
"version")) {
176 SWC_SHOULD_NOT_INLINE
181 std::filesystem::path fname;
182 if(name.front() !=
'/' && name.front() !=
'.')
183 fname =
get_str(
"swc.cfg.path");
188 SWC_THROWF(ENOENT,
"cfg file=%s not found", fname.string().c_str());
195 SWC_SHOULD_NOT_INLINE
197 if(!fileprop || !
has(fileprop))
201 auto ptr = get<Property::Value_strings>(fileprop);
206 for(
auto it=files.
cbegin(); it != files.
cend(); ++it) {
208 if(it->front() !=
'/' && it->front() !=
'.')
209 fname.append(
get_str(
"swc.cfg.path"));
216 auto it_found = std::find(
223 << fileprop <<
" has bad cfg file='" << *it <<
"': " << e;
231 SWC_SHOULD_NOT_INLINE
232 void write_pid(
const std::filesystem::path& pid_file,
size_t pid) {
235 std::ofstream pid_file_buff(pid_file, std::ios::out);
236 if(pid_file_buff.is_open()) {
238 pid_file_buff.close();
242 std::cerr <<
"Problem writing pid-file=" << pid_file;
244 std::cerr << std::endl;
249 SWC_SHOULD_NOT_INLINE
250 std::string get_old_pid(
const std::filesystem::path& pid_file) {
255 std::ifstream buffer(pid_file);
256 if(buffer.is_open()) {
261 ec = std::error_code(errno?errno:ECANCELED, std::generic_category());
264 std::cerr <<
"Problem reading pid-file=" << pid_file;
266 std::cerr << std::endl;
272 SWC_SHOULD_NOT_INLINE
273 void check_pid(
const std::filesystem::path& pid_file,
274 const std::string& install_path,
275 const std::string& executable) {
276 auto old_pid = get_old_pid(pid_file);
279 std::filesystem::path pid_exe(
"/proc/");
280 pid_exe.concat(old_pid);
281 pid_exe.concat(
"/exe");
284 auto path = std::filesystem::read_symlink(pid_exe, ec);
286 std::filesystem::path prog(install_path +
"/bin/" + executable);
288 prog.string().size())) {
289 std::cerr <<
"Problem executing '" << executable
290 <<
"', process already running-pid=" << old_pid
291 <<
", stop it first" << std::endl;
297 std::cerr <<
"Problem reading running-pid='" << pid_exe <<
"' ";
299 std::cerr << std::endl;
305 SWC_SHOULD_NOT_INLINE
306 void update_pid(
const std::string& install_path,
307 const std::string& executable,
311 pid_file.concat(executable);
313 pid_file.concat(
".");
316 pid_file.concat(
".pid");
318 check_pid(pid_file, install_path, executable);
319 write_pid(pid_file, pid);
321 std::cout <<
"Executing '"<< executable
322 <<
"' with pid-file=" << pid_file << std::endl;
325 SWC_SHOULD_NOT_INLINE
326 void print_init(
const Settings* settings) {
330 <<
"Initialized " << settings->executable <<
' '
333 <<
"Process Settings: \n");
339 SWC_SHOULD_NOT_INLINE
341 bool daemon =
has(
"daemon");
342 #if defined(__MINGW64__) || defined(_WIN32)
350 size_t pid = getpid();
376 else if(strstr(usage,
"%s"))
377 tmp.append(format_unsafe(usage,
executable.c_str()));
386 SWC_SHOULD_NOT_INLINE
387 time_t file_mtime(
const char* filename) {
390 if(::stat(filename, &statbuf)) {
395 return statbuf.st_mtime;
399 SWC_SHOULD_NOT_INLINE
404 time_t mtime = file_mtime(dyn.filename.c_str());
405 if(mtime && dyn.modified != mtime) {
406 dyn.modified = mtime;
void reload(const std::string &fname, const Config::ParserConfig &filedesc, const Config::ParserConfig &cmddesc)
void own_options(Options &opts)
ParserConfig & add(const ParserConfig &other_cfg)
Parser::Options m_cmd_args
void daemon(const std::string &logs_path)
int str_cmp(const char *s1, const char *s2) noexcept SWC_ATTRIBS((SWC_ATTRIB_O3))
Property::Value_enum_g::Ptr g_enum(const int32_t &v, Property::Value_enum_g::OnChg_t &&cb, Property::Value_enum_g::FromString_t &&from_string, Property::Value_enum_g::Repr_t &&repr)
void init_process(bool with_pid_file, const char *port_cfg=nullptr)
Property::Value_bool_g::Ptr g_boo(const bool &v)
#define SWC_LOGF(priority, fmt,...)
#define SWC_LOG_OUT(pr, _code_)
#define USE_SWC_PATH_LOG(_default_)
void exists(const ConnHandlerPtr &conn, const Event::Ptr &ev)
const char * get_text(const int err) noexcept
void init_app_options(Settings *settings)
Core::Vector< DynFile > m_dyn_files
bool get_gbool(const char *name) const
#define USE_SWC_PATH_RUN(_default_)
bool defaulted(const char *name) const
ParserConfig cmdline_desc
Property::Value_bool::Ptr boo(const bool &v)
uint16_t get_i16(const char *name) const
const char * swcdb_copyrights() noexcept
void parse_file(const std::string &fname, const char *onchg)
void initialize(const std::string &name)
#define SWC_CURRENT_EXCEPTION(_msg_)
std::string usage_str(const char *usage=nullptr)
The SWC-DB C++ namespace 'SWC'.
void remove(int &err, cid_t cid)
void parse_cmdline(int argc, char *argv[])
#define USE_SWC_PATH_ETC(_default_)
bool SWC_PURE_FUNC has(const char *name) const noexcept
Property::Value_strings::Ptr strs(Strings &&v)
#define SWC_THROWF(_code_, _fmt_,...)
ParserConfig &SWC_CONST_FUNC add_options()
Property::Value_string::Ptr str(std::string &&v)
void load(const std::string &fname, const Config::ParserConfig &filedesc, const Config::ParserConfig &cmddesc, bool allow_unregistered=false, bool only_guarded=false)
void load_from(const Config::Parser::Options &opts, bool only_guarded=false)
const char * swcdb_version() noexcept
static uint8_t SWC_PURE_FUNC from_string(const std::string &loglevel) noexcept
std::string format(const char *fmt,...) __attribute__((format(printf
#define SWC_QUICK_EXIT(_CODE_)
Ptr zero_token() noexcept
void init(int argc, char *argv[], init_option_t app, init_option_t post_cmd_args)
std::string get_str(const char *name) const
constexpr SWC_CAN_INLINE const_iterator cend() const noexcept
void init_post_cmd_args(Settings *settings)
void parse_args(int argc, char *argv[])
void load_files_by(const char *fileprop, bool allow_unregistered)
void init_option_t(Settings *)
void print(std::ostream &out, int err)
constexpr SWC_CAN_INLINE const_iterator cbegin() const noexcept
SWC_CAN_INLINE std::string to_string(const BitFieldInt< T, SZ > &v)
bool get_bool(const char *name) const
#define SWC_LOG_CURRENT_EXCEPTION(_s_)
constexpr SWC_CAN_INLINE void set_level(uint8_t level) noexcept
void check_dynamic_files() noexcept
static std::string repr(uint8_t priority)
ParserConfig & definition(const char *u)