2021-09-22 08:15:20 +00:00
/*
* Copyright ( c ) 2019 TAOS Data , Inc . < jhtao @ taosdata . com >
*
* This program is free software : you can use , redistribute , and / or modify
* it under the terms of the GNU Affero General Public License , version 3
* or later ( " AGPL " ) , as published by the Free Software Foundation .
*
* This program is distributed in the hope that it will be useful , but WITHOUT
* ANY WARRANTY ; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE .
*
* You should have received a copy of the GNU Affero General Public License
* along with this program . If not , see < http : //www.gnu.org/licenses/>.
*/
2021-11-01 12:38:50 +00:00
# define _DEFAULT_SOURCE
2022-05-12 09:57:38 +00:00
# include "dmMgmt.h"
2022-09-26 08:18:48 +00:00
# include "mnode.h"
2022-10-13 03:56:16 +00:00
# include "tconfig.h"
2022-12-08 01:41:42 +00:00
# include "tglobal.h"
2023-03-27 03:06:10 +00:00
# include "version.h"
2023-07-07 00:34:19 +00:00
# ifdef TD_JEMALLOC_ENABLED
# include "jemalloc/jemalloc.h"
# endif
2024-03-29 06:19:44 +00:00
# include "dmUtil.h"
2021-09-22 08:15:20 +00:00
2023-04-07 09:10:39 +00:00
# if defined(CUS_NAME) || defined(CUS_PROMPT) || defined(CUS_EMAIL)
# include "cus_name.h"
# else
# ifndef CUS_NAME
2024-04-08 02:31:49 +00:00
# define CUS_NAME "TDengine"
2023-04-07 09:10:39 +00:00
# endif
# ifndef CUS_PROMPT
2024-04-08 02:31:49 +00:00
# define CUS_PROMPT "taos"
2023-04-07 09:10:39 +00:00
# endif
# ifndef CUS_EMAIL
2024-04-08 02:31:49 +00:00
# define CUS_EMAIL "<support@taosdata.com>"
2023-04-07 09:10:39 +00:00
# endif
# endif
2022-10-13 03:56:16 +00:00
// clang-format off
2022-04-26 03:43:47 +00:00
# define DM_APOLLO_URL "The apollo string to use when configuring the server, such as: -a 'jsonFile:. / tests / cfg.json', cfg.json text can be '{\"fqdn\":\"td1\"}'."
# define DM_CFG_DIR "Configuration directory."
# define DM_DMP_CFG "Dump configuration."
2022-09-26 08:32:14 +00:00
# define DM_SDB_INFO "Dump sdb info."
2022-04-26 03:43:47 +00:00
# define DM_ENV_CMD "The env cmd variable string to use when configuring the server, such as: -e 'TAOS_FQDN=td1'."
# define DM_ENV_FILE "The env variable file path to use when configuring the server, default is '. / .env', .env text can be 'TAOS_FQDN=td1'."
# define DM_MACHINE_CODE "Get machine code."
# define DM_VERSION "Print program version."
# define DM_EMAIL "<support@taosdata.com>"
2023-02-17 09:40:14 +00:00
# define DM_MEM_DBG "Enable memory debug"
2024-03-29 06:19:44 +00:00
# define DM_SET_ENCRYPTKEY "Set encrypt key. such as: -y 1234567890abcdef, the length should be less or equal to 16."
2022-10-13 03:56:16 +00:00
// clang-format on
2021-11-22 02:03:41 +00:00
static struct {
2022-07-29 08:36:42 +00:00
# ifdef WINDOWS
2022-10-13 03:56:16 +00:00
bool winServiceMode ;
2022-07-29 08:36:42 +00:00
# endif
2022-04-13 06:00:56 +00:00
bool dumpConfig ;
2022-09-26 08:18:48 +00:00
bool dumpSdb ;
2022-04-13 06:00:56 +00:00
bool generateGrant ;
2023-02-17 09:40:14 +00:00
bool memDbg ;
2024-04-08 02:31:49 +00:00
bool checkS3 ;
2022-04-13 06:00:56 +00:00
bool printAuth ;
bool printVersion ;
2022-04-26 03:43:47 +00:00
bool printHelp ;
2022-04-13 06:00:56 +00:00
char envFile [ PATH_MAX ] ;
char apolloUrl [ PATH_MAX ] ;
2022-04-25 05:57:55 +00:00
const char * * envCmd ;
2022-04-13 06:00:56 +00:00
SArray * pArgs ; // SConfigPair
2022-12-30 05:30:54 +00:00
int64_t startTime ;
2024-03-29 02:48:49 +00:00
bool generateCode ;
char encryptKey [ ENCRYPT_KEY_LEN + 1 ] ;
2022-03-12 15:08:48 +00:00
} global = { 0 } ;
2021-11-20 16:13:35 +00:00
2024-07-24 08:36:57 +00:00
static void dmSetDebugFlag ( int32_t signum , void * sigInfo , void * context ) { ( void ) taosSetGlobalDebugFlag ( 143 ) ; }
2022-12-08 01:41:42 +00:00
static void dmSetAssert ( int32_t signum , void * sigInfo , void * context ) { tsAssert = 1 ; }
static void dmStopDnode ( int signum , void * sigInfo , void * context ) {
// taosIgnSignal(SIGUSR1);
// taosIgnSignal(SIGUSR2);
2024-07-29 11:41:44 +00:00
( void ) taosIgnSignal ( SIGTERM ) ;
( void ) taosIgnSignal ( SIGHUP ) ;
( void ) taosIgnSignal ( SIGINT ) ;
( void ) taosIgnSignal ( SIGABRT ) ;
( void ) taosIgnSignal ( SIGBREAK ) ;
2022-12-08 01:41:42 +00:00
dInfo ( " shut down signal is %d " , signum ) ;
# ifndef WINDOWS
dInfo ( " sender PID:%d cmdline:%s " , ( ( siginfo_t * ) sigInfo ) - > si_pid ,
taosGetCmdlineByPID ( ( ( siginfo_t * ) sigInfo ) - > si_pid ) ) ;
# endif
dmStop ( ) ;
}
2021-11-20 16:13:35 +00:00
2022-12-30 05:30:54 +00:00
void dmLogCrash ( int signum , void * sigInfo , void * context ) {
2023-05-15 11:39:03 +00:00
// taosIgnSignal(SIGTERM);
// taosIgnSignal(SIGHUP);
// taosIgnSignal(SIGINT);
// taosIgnSignal(SIGBREAK);
# ifndef WINDOWS
2024-07-29 11:41:44 +00:00
( void ) taosIgnSignal ( SIGBUS ) ;
2023-05-15 11:39:03 +00:00
# endif
2024-07-29 11:41:44 +00:00
( void ) taosIgnSignal ( SIGABRT ) ;
( void ) taosIgnSignal ( SIGFPE ) ;
( void ) taosIgnSignal ( SIGSEGV ) ;
2023-05-15 11:39:03 +00:00
2023-03-27 03:06:10 +00:00
char * pMsg = NULL ;
2022-12-30 05:30:54 +00:00
const char * flags = " UTL FATAL " ;
ELogLevel level = DEBUG_FATAL ;
int32_t dflag = 255 ;
2023-03-27 03:06:10 +00:00
int64_t msgLen = - 1 ;
2022-12-30 05:30:54 +00:00
if ( tsEnableCrashReport ) {
if ( taosGenCrashJsonMsg ( signum , & pMsg , dmGetClusterId ( ) , global . startTime ) ) {
taosPrintLog ( flags , level , dflag , " failed to generate crash json msg " ) ;
goto _return ;
} else {
2023-03-27 03:06:10 +00:00
msgLen = strlen ( pMsg ) ;
2022-12-30 05:30:54 +00:00
}
}
2023-03-27 03:06:10 +00:00
2022-12-30 05:30:54 +00:00
_return :
taosLogCrashInfo ( " taosd " , pMsg , msgLen , signum , sigInfo ) ;
2023-01-04 11:12:16 +00:00
2023-01-10 01:28:04 +00:00
# ifdef _TD_DARWIN_64
2023-01-04 11:12:16 +00:00
exit ( signum ) ;
2023-01-10 01:28:04 +00:00
# elif defined(WINDOWS)
exit ( signum ) ;
# endif
2022-12-30 05:30:54 +00:00
}
2022-04-13 06:00:56 +00:00
static void dmSetSignalHandle ( ) {
2024-07-29 11:41:44 +00:00
( void ) taosSetSignal ( SIGUSR1 , dmSetDebugFlag ) ;
( void ) taosSetSignal ( SIGUSR2 , dmSetAssert ) ;
( void ) taosSetSignal ( SIGTERM , dmStopDnode ) ;
( void ) taosSetSignal ( SIGHUP , dmStopDnode ) ;
( void ) taosSetSignal ( SIGINT , dmStopDnode ) ;
( void ) taosSetSignal ( SIGBREAK , dmStopDnode ) ;
2022-04-22 01:54:27 +00:00
# ifndef WINDOWS
2024-07-29 11:41:44 +00:00
( void ) taosSetSignal ( SIGTSTP , dmStopDnode ) ;
( void ) taosSetSignal ( SIGQUIT , dmStopDnode ) ;
2022-04-22 01:54:27 +00:00
# endif
2022-12-23 01:22:14 +00:00
2022-12-30 07:56:37 +00:00
# ifndef WINDOWS
2024-07-29 11:41:44 +00:00
( void ) taosSetSignal ( SIGBUS , dmLogCrash ) ;
2023-03-27 03:06:10 +00:00
# endif
2024-07-29 11:41:44 +00:00
( void ) taosSetSignal ( SIGABRT , dmLogCrash ) ;
( void ) taosSetSignal ( SIGFPE , dmLogCrash ) ;
( void ) taosSetSignal ( SIGSEGV , dmLogCrash ) ;
2021-10-04 12:47:39 +00:00
}
2022-04-13 06:00:56 +00:00
static int32_t dmParseArgs ( int32_t argc , char const * argv [ ] ) {
2022-12-30 05:30:54 +00:00
global . startTime = taosGetTimestampMs ( ) ;
2022-04-25 05:57:55 +00:00
int32_t cmdEnvIndex = 0 ;
2022-04-26 08:23:51 +00:00
if ( argc < 2 ) return 0 ;
2023-03-27 03:06:10 +00:00
2022-05-16 13:36:29 +00:00
global . envCmd = taosMemoryMalloc ( ( argc - 1 ) * sizeof ( char * ) ) ;
memset ( global . envCmd , 0 , ( argc - 1 ) * sizeof ( char * ) ) ;
2022-02-22 11:49:11 +00:00
for ( int32_t i = 1 ; i < argc ; + + i ) {
2021-11-22 02:03:41 +00:00
if ( strcmp ( argv [ i ] , " -c " ) = = 0 ) {
if ( i < argc - 1 ) {
if ( strlen ( argv [ + + i ] ) > = PATH_MAX ) {
printf ( " config file path overflow " ) ;
2024-07-18 00:48:27 +00:00
return TSDB_CODE_INVALID_CFG ;
2021-11-22 02:03:41 +00:00
}
2022-02-23 02:35:53 +00:00
tstrncpy ( configDir , argv [ i ] , PATH_MAX ) ;
2021-11-22 02:03:41 +00:00
} else {
2021-11-23 11:54:17 +00:00
printf ( " '-c' requires a parameter, default is %s \n " , configDir ) ;
2024-07-18 00:48:27 +00:00
return TSDB_CODE_INVALID_CFG ;
2021-11-22 02:03:41 +00:00
}
2022-03-29 11:53:10 +00:00
} else if ( strcmp ( argv [ i ] , " -a " ) = = 0 ) {
2024-04-08 02:31:49 +00:00
if ( i < argc - 1 ) {
2024-01-23 08:33:12 +00:00
if ( strlen ( argv [ + + i ] ) > = PATH_MAX ) {
printf ( " apollo url overflow " ) ;
2024-07-18 00:48:27 +00:00
return TSDB_CODE_INVALID_CFG ;
2024-01-23 08:33:12 +00:00
}
tstrncpy ( global . apolloUrl , argv [ i ] , PATH_MAX ) ;
} else {
printf ( " '-a' requires a parameter \n " ) ;
2024-07-18 00:48:27 +00:00
return TSDB_CODE_INVALID_CFG ;
2024-01-23 08:33:12 +00:00
}
2022-09-26 08:18:48 +00:00
} else if ( strcmp ( argv [ i ] , " -s " ) = = 0 ) {
global . dumpSdb = true ;
2022-04-25 05:57:55 +00:00
} else if ( strcmp ( argv [ i ] , " -E " ) = = 0 ) {
2024-04-08 02:31:49 +00:00
if ( i < argc - 1 ) {
2024-01-23 09:43:23 +00:00
if ( strlen ( argv [ + + i ] ) > = PATH_MAX ) {
printf ( " env file path overflow " ) ;
2024-07-18 00:48:27 +00:00
return TSDB_CODE_INVALID_CFG ;
2024-01-23 09:43:23 +00:00
}
tstrncpy ( global . envFile , argv [ i ] , PATH_MAX ) ;
} else {
printf ( " '-E' requires a parameter \n " ) ;
2024-07-18 00:48:27 +00:00
return TSDB_CODE_INVALID_CFG ;
2024-01-23 09:43:23 +00:00
}
2022-03-31 07:11:09 +00:00
} else if ( strcmp ( argv [ i ] , " -k " ) = = 0 ) {
global . generateGrant = true ;
2024-03-29 02:48:49 +00:00
} else if ( strcmp ( argv [ i ] , " -y " ) = = 0 ) {
global . generateCode = true ;
2024-07-16 11:00:12 +00:00
if ( i < argc - 1 ) {
2024-04-08 07:07:19 +00:00
int32_t len = strlen ( argv [ + + i ] ) ;
if ( len < ENCRYPT_KEY_LEN_MIN ) {
2024-05-21 01:57:33 +00:00
printf ( " ERROR: Encrypt key should be at least %d characters \n " , ENCRYPT_KEY_LEN_MIN ) ;
2024-07-18 00:48:27 +00:00
return TSDB_CODE_INVALID_CFG ;
2024-04-08 07:07:19 +00:00
}
if ( len > ENCRYPT_KEY_LEN ) {
2024-05-21 01:57:33 +00:00
printf ( " ERROR: Encrypt key overflow, it should be at most %d characters \n " , ENCRYPT_KEY_LEN ) ;
2024-07-18 00:48:27 +00:00
return TSDB_CODE_INVALID_CFG ;
2024-03-29 02:48:49 +00:00
}
tstrncpy ( global . encryptKey , argv [ i ] , ENCRYPT_KEY_LEN ) ;
} else {
printf ( " '-y' requires a parameter \n " ) ;
2024-07-18 00:48:27 +00:00
return TSDB_CODE_INVALID_CFG ;
2024-03-29 02:48:49 +00:00
}
2022-03-29 11:53:10 +00:00
} else if ( strcmp ( argv [ i ] , " -C " ) = = 0 ) {
global . dumpConfig = true ;
2021-11-22 02:03:41 +00:00
} else if ( strcmp ( argv [ i ] , " -V " ) = = 0 ) {
2022-03-12 15:08:48 +00:00
global . printVersion = true ;
2022-10-13 03:56:16 +00:00
# ifdef WINDOWS
2022-07-29 08:36:42 +00:00
} else if ( strcmp ( argv [ i ] , " --win_service " ) = = 0 ) {
global . winServiceMode = true ;
2022-10-13 03:56:16 +00:00
# endif
2022-04-25 05:57:55 +00:00
} else if ( strcmp ( argv [ i ] , " -e " ) = = 0 ) {
global . envCmd [ cmdEnvIndex ] = argv [ + + i ] ;
cmdEnvIndex + + ;
2023-02-17 09:40:14 +00:00
} else if ( strcmp ( argv [ i ] , " -dm " ) = = 0 ) {
global . memDbg = true ;
2024-04-08 02:31:49 +00:00
} else if ( strcmp ( argv [ i ] , " --checks3 " ) = = 0 ) {
global . checkS3 = true ;
2022-05-16 13:36:29 +00:00
} else if ( strcmp ( argv [ i ] , " -h " ) = = 0 | | strcmp ( argv [ i ] , " --help " ) = = 0 | | strcmp ( argv [ i ] , " --usage " ) = = 0 | |
2023-02-17 09:40:14 +00:00
strcmp ( argv [ i ] , " -? " ) = = 0 ) {
2022-04-26 03:43:47 +00:00
global . printHelp = true ;
2021-11-22 02:03:41 +00:00
} else {
}
2021-10-04 09:44:39 +00:00
}
2021-11-22 02:03:41 +00:00
return 0 ;
}
2022-12-08 02:50:24 +00:00
static void dmPrintArgs ( int32_t argc , char const * argv [ ] ) {
char path [ 1024 ] = { 0 } ;
taosGetCwd ( path , sizeof ( path ) ) ;
char args [ 1024 ] = { 0 } ;
int32_t arglen = snprintf ( args , sizeof ( args ) , " %s " , argv [ 0 ] ) ;
for ( int32_t i = 1 ; i < argc ; + + i ) {
arglen = arglen + snprintf ( args + arglen , sizeof ( args ) - arglen , " %s " , argv [ i ] ) ;
}
dInfo ( " startup path:%s args:%s " , path , args ) ;
}
2022-04-14 05:44:40 +00:00
static void dmGenerateGrant ( ) { mndGenerateMachineCode ( ) ; }
2022-03-29 11:53:10 +00:00
2022-04-13 06:00:56 +00:00
static void dmPrintVersion ( ) {
2024-05-23 09:17:18 +00:00
printf ( " %s \n taosd version: %s compatible_version: %s \n " , TD_PRODUCT_NAME , version , compatible_version ) ;
printf ( " git: %s \n " , gitinfo ) ;
2023-03-27 03:06:10 +00:00
# ifdef TD_ENTERPRISE
2024-06-18 00:44:57 +00:00
printf ( " gitOfInternal: %s \n " , gitinfoOfInternal ) ;
2023-03-27 03:06:10 +00:00
# endif
2024-05-23 09:17:18 +00:00
printf ( " build: %s \n " , buildinfo ) ;
2022-03-29 11:53:10 +00:00
}
2022-04-26 03:43:47 +00:00
static void dmPrintHelp ( ) {
char indent [ ] = " " ;
printf ( " Usage: taosd [OPTION...] \n \n " ) ;
printf ( " %s%s%s%s \n " , indent , " -a, " , indent , DM_APOLLO_URL ) ;
printf ( " %s%s%s%s \n " , indent , " -c, " , indent , DM_CFG_DIR ) ;
2022-09-26 08:32:14 +00:00
printf ( " %s%s%s%s \n " , indent , " -s, " , indent , DM_SDB_INFO ) ;
2022-04-26 03:43:47 +00:00
printf ( " %s%s%s%s \n " , indent , " -C, " , indent , DM_DMP_CFG ) ;
printf ( " %s%s%s%s \n " , indent , " -e, " , indent , DM_ENV_CMD ) ;
printf ( " %s%s%s%s \n " , indent , " -E, " , indent , DM_ENV_FILE ) ;
printf ( " %s%s%s%s \n " , indent , " -k, " , indent , DM_MACHINE_CODE ) ;
2024-03-29 02:48:49 +00:00
printf ( " %s%s%s%s \n " , indent , " -y, " , indent , DM_SET_ENCRYPTKEY ) ;
2023-02-17 09:40:14 +00:00
printf ( " %s%s%s%s \n " , indent , " -dm, " , indent , DM_MEM_DBG ) ;
2022-04-26 03:43:47 +00:00
printf ( " %s%s%s%s \n " , indent , " -V, " , indent , DM_VERSION ) ;
printf ( " \n \n Report bugs to %s. \n " , DM_EMAIL ) ;
}
2022-04-13 06:00:56 +00:00
static void dmDumpCfg ( ) {
2022-03-29 11:53:10 +00:00
SConfig * pCfg = taosGetCfg ( ) ;
2022-04-22 07:50:29 +00:00
cfgDumpCfg ( pCfg , 0 , true ) ;
2022-03-29 11:53:10 +00:00
}
2024-04-08 02:31:49 +00:00
static int32_t dmCheckS3 ( ) {
int32_t code = 0 ;
SConfig * pCfg = taosGetCfg ( ) ;
cfgDumpCfgS3 ( pCfg , 0 , true ) ;
# if defined(USE_S3)
extern int32_t s3CheckCfg ( ) ;
code = s3CheckCfg ( ) ;
# endif
return code ;
}
2022-04-13 06:00:56 +00:00
static int32_t dmInitLog ( ) {
2024-04-08 02:31:49 +00:00
return taosCreateLog ( CUS_PROMPT " dlog " , 1 , configDir , global . envCmd , global . envFile , global . apolloUrl , global . pArgs ,
0 ) ;
2022-03-29 13:13:09 +00:00
}
2022-04-25 05:57:55 +00:00
static void taosCleanupArgs ( ) {
2022-12-29 06:12:09 +00:00
if ( global . envCmd ! = NULL ) taosMemoryFreeClear ( global . envCmd ) ;
2022-04-25 05:57:55 +00:00
}
2021-11-22 02:03:41 +00:00
int main ( int argc , char const * argv [ ] ) {
2024-07-16 01:04:16 +00:00
int32_t code = 0 ;
2023-07-07 00:34:19 +00:00
# ifdef TD_JEMALLOC_ENABLED
bool jeBackgroundThread = true ;
mallctl ( " background_thread " , NULL , NULL , & jeBackgroundThread , sizeof ( bool ) ) ;
# endif
2022-07-20 00:39:52 +00:00
if ( ! taosCheckSystemIsLittleEnd ( ) ) {
printf ( " failed to start since on non-little-end machines \n " ) ;
2022-03-09 02:46:31 +00:00
return - 1 ;
}
2024-07-16 01:04:16 +00:00
if ( ( code = dmParseArgs ( argc , argv ) ) ! = 0 ) {
2024-07-16 11:00:12 +00:00
// printf("failed to start since parse args error\n");
2022-04-25 05:57:55 +00:00
taosCleanupArgs ( ) ;
2024-07-16 01:04:16 +00:00
return code ;
2021-11-22 02:03:41 +00:00
}
2022-07-29 08:36:42 +00:00
# ifdef WINDOWS
2022-10-13 03:56:16 +00:00
int mainWindows ( int argc , char * * argv ) ;
2022-07-29 08:36:42 +00:00
if ( global . winServiceMode ) {
stratWindowsService ( mainWindows ) ;
} else {
return mainWindows ( argc , argv ) ;
}
return 0 ;
}
2022-10-13 03:56:16 +00:00
int mainWindows ( int argc , char * * argv ) {
2024-07-18 08:23:38 +00:00
int32_t code = 0 ;
2022-07-29 08:36:42 +00:00
# endif
2022-03-12 15:08:48 +00:00
if ( global . generateGrant ) {
2022-04-13 06:00:56 +00:00
dmGenerateGrant ( ) ;
2022-04-25 05:57:55 +00:00
taosCleanupArgs ( ) ;
2022-02-23 02:35:53 +00:00
return 0 ;
}
2022-04-26 03:43:47 +00:00
if ( global . printHelp ) {
dmPrintHelp ( ) ;
taosCleanupArgs ( ) ;
return 0 ;
}
2022-03-12 15:08:48 +00:00
if ( global . printVersion ) {
2022-04-13 06:00:56 +00:00
dmPrintVersion ( ) ;
2022-04-25 05:57:55 +00:00
taosCleanupArgs ( ) ;
2022-02-23 02:35:53 +00:00
return 0 ;
2021-11-22 02:03:41 +00:00
}
2023-02-17 09:40:14 +00:00
# if defined(LINUX)
if ( global . memDbg ) {
2024-07-18 05:29:35 +00:00
code = taosMemoryDbgInit ( ) ;
2023-02-17 09:40:14 +00:00
if ( code ) {
printf ( " failed to init memory dbg, error:%s \n " , tstrerror ( code ) ) ;
return code ;
}
2023-03-27 03:06:10 +00:00
tsAsyncLog = false ;
2023-02-17 09:40:14 +00:00
printf ( " memory dbg enabled \n " ) ;
}
# endif
2024-07-16 11:00:12 +00:00
if ( global . generateCode ) {
2024-05-21 01:57:33 +00:00
bool toLogFile = false ;
2024-07-16 01:04:16 +00:00
if ( ( code = taosReadDataFolder ( configDir , global . envCmd , global . envFile , global . apolloUrl , global . pArgs ) ) ! = 0 ) {
encryptError ( " failed to generate encrypt code since dataDir can not be set from cfg file,reason:%s " ,
tstrerror ( code ) ) ;
return code ;
2024-05-21 01:57:33 +00:00
} ;
2024-07-16 01:04:16 +00:00
TdFilePtr pFile ;
2024-07-16 11:00:12 +00:00
if ( ( code = dmCheckRunning ( tsDataDir , & pFile ) ) ! = 0 ) {
encryptError ( " failed to generate encrypt code since taosd is running, please stop it first, reason:%s " ,
tstrerror ( code ) ) ;
2024-07-16 01:04:16 +00:00
return code ;
2024-05-21 01:57:33 +00:00
}
int ret = dmUpdateEncryptKey ( global . encryptKey , toLogFile ) ;
taosCloseLog ( ) ;
taosCleanupArgs ( ) ;
return ret ;
}
2023-02-17 09:40:14 +00:00
2024-07-17 02:51:28 +00:00
if ( ( code = dmInitLog ( ) ) ! = 0 ) {
2022-05-20 09:36:42 +00:00
printf ( " failed to start since init log error \n " ) ;
2022-04-25 05:57:55 +00:00
taosCleanupArgs ( ) ;
2024-07-17 02:51:28 +00:00
return code ;
2021-11-22 02:03:41 +00:00
}
2022-12-08 02:50:24 +00:00
dmPrintArgs ( argc , argv ) ;
2024-07-17 02:51:28 +00:00
if ( ( code = taosInitCfg ( configDir , global . envCmd , global . envFile , global . apolloUrl , global . pArgs , 0 ) ) ! = 0 ) {
2022-03-29 11:53:10 +00:00
dError ( " failed to start since read config error " ) ;
2022-05-20 09:36:42 +00:00
taosCloseLog ( ) ;
2022-04-25 05:57:55 +00:00
taosCleanupArgs ( ) ;
2024-07-17 02:51:28 +00:00
return code ;
2021-11-22 02:03:41 +00:00
}
2022-10-13 03:56:16 +00:00
2024-07-17 02:51:28 +00:00
if ( ( code = taosConvInit ( ) ) ! = 0 ) {
2022-12-07 14:24:47 +00:00
dError ( " failed to init conv " ) ;
taosCloseLog ( ) ;
taosCleanupArgs ( ) ;
2024-07-17 02:51:28 +00:00
return code ;
2022-12-07 14:24:47 +00:00
}
2021-11-22 02:03:41 +00:00
2024-04-08 02:31:49 +00:00
if ( global . checkS3 ) {
2024-07-18 05:30:39 +00:00
code = dmCheckS3 ( ) ;
2024-04-08 02:31:49 +00:00
taosCleanupCfg ( ) ;
taosCloseLog ( ) ;
taosCleanupArgs ( ) ;
taosConvDestroy ( ) ;
return code ;
}
2022-03-12 15:08:48 +00:00
if ( global . dumpConfig ) {
2022-04-13 06:00:56 +00:00
dmDumpCfg ( ) ;
2022-02-24 11:06:39 +00:00
taosCleanupCfg ( ) ;
2022-03-12 14:56:56 +00:00
taosCloseLog ( ) ;
2022-04-25 05:57:55 +00:00
taosCleanupArgs ( ) ;
2022-10-19 09:53:01 +00:00
taosConvDestroy ( ) ;
2021-11-22 02:03:41 +00:00
return 0 ;
}
2022-09-26 08:18:48 +00:00
if ( global . dumpSdb ) {
mndDumpSdb ( ) ;
taosCleanupCfg ( ) ;
taosCloseLog ( ) ;
taosCleanupArgs ( ) ;
2022-10-19 09:53:01 +00:00
taosConvDestroy ( ) ;
2022-09-26 08:18:48 +00:00
return 0 ;
}
2022-10-19 09:53:01 +00:00
osSetProcPath ( argc , ( char * * ) argv ) ;
2022-04-25 05:57:55 +00:00
taosCleanupArgs ( ) ;
2022-05-16 13:36:29 +00:00
2024-07-17 02:51:28 +00:00
if ( ( code = dmGetEncryptKey ( ) ) ! = 0 ) {
2024-06-04 05:07:56 +00:00
dError ( " failed to start since failed to get encrypt key " ) ;
taosCloseLog ( ) ;
taosCleanupArgs ( ) ;
2024-07-17 02:51:28 +00:00
return code ;
2024-06-04 05:07:56 +00:00
} ;
2024-07-17 02:51:28 +00:00
if ( ( code = dmInit ( ) ) ! = 0 ) {
if ( code = = TSDB_CODE_NOT_FOUND ) {
2023-07-14 11:19:46 +00:00
dError ( " failed to init dnode since unsupported platform, please visit https://www.taosdata.com for support " ) ;
} else {
2024-07-17 02:51:28 +00:00
dError ( " failed to init dnode since %s " , tstrerror ( code ) ) ;
2023-07-14 11:19:46 +00:00
}
2022-12-28 02:20:18 +00:00
taosCleanupCfg ( ) ;
taosCloseLog ( ) ;
taosConvDestroy ( ) ;
2024-07-17 02:51:28 +00:00
return code ;
2022-05-16 13:36:29 +00:00
}
2022-07-08 07:20:15 +00:00
dInfo ( " start to init service " ) ;
2022-05-16 13:36:29 +00:00
dmSetSignalHandle ( ) ;
2023-07-19 07:30:14 +00:00
tsDndStart = taosGetTimestampMs ( ) ;
2023-07-23 15:25:58 +00:00
tsDndStartOsUptime = taosGetOsUptime ( ) ;
2024-07-16 11:00:12 +00:00
code = dmRun ( ) ;
2022-05-16 13:36:29 +00:00
dInfo ( " shutting down the service " ) ;
dmCleanup ( ) ;
return code ;
2021-11-22 02:03:41 +00:00
}