00001 /******************************************************************************/ 00002 /* */ 00003 /* X r d G n s M a i n . c c */ 00004 /* */ 00005 /* (c) 2007 by the Board of Trustees of the Leland Stanford, Jr., University */ 00006 /* All Rights Reserved. See XrdInfo.cc for complete License Terms */ 00007 /* Produced by Andrew Hanushevsky for Stanford University under contract */ 00008 /* DE-AC03-76-SFO0515 with the Department of Energy */ 00009 /******************************************************************************/ 00010 00011 // $Id: XrdCnsMain.cc 32231 2010-02-05 18:24:46Z ganis $ 00012 00013 const char *XrdCnsMainCVSID = "$Id: XrdCnsMain.cc 32231 2010-02-05 18:24:46Z ganis $"; 00014 00015 /* This is the Cluster Name Space interface. The syntax is: 00016 00017 XrdCnsd [options] [[xroot://]<host[:port]>[/[/prefix]] . . .] 00018 00019 options: [-a <apath>] [-b <bpath>] [-B <bpath>] [-c] [-d] [-e <epath>] 00020 00021 [-i <tspec>] [-I <tspec>] [-l <lfile>] [-p <port>] [-q <lim>] [-R] 00022 Where: 00023 -a The admin path where the event log is placed and where named 00024 sockets are created. If not specified, the admin path comes from 00025 the XRDADMINPATH env variable. Otherwise, /tmp is used. This option 00026 is valid only for command line use. 00027 00028 -b The archive (i.e., backup) path to use. If not specified, no backup 00029 is done. Data is written to "<bpath>/cns/<host>". By default, the 00030 backups are written to each redirector. By prefixing <bpath> with 00031 <host[:port]:> then backups are written to the specified host:port. 00032 If <port> is omitted the the specified or default -p value is used. 00033 Note that this backup can be used to create an inventory file. 00034 00035 -B Same as -b *except* that only the inventory is maintained (i.e., no 00036 composite name space is created). 00037 00038 -c Specified the config file name. By defaults this comes from the envar 00039 XRDCONFIGFN set by the underlying xrootd. Note that if -R is specified 00040 then -c must be specified as there is no underlying xrootd. 00041 00042 -d Turns on debugging mode. Valid only via command line. 00043 00044 -D Sets the client library debug value. Specify an number -2 to 3. 00045 00046 -e The directory where the event logs are to be written. By default 00047 this is whatever <apath> becomes. 00048 00049 -i The interval between forced log archiving. Default is 20m (minutes). 00050 00051 -I The time interval, in seconds, between checks for the inventory file. 00052 00053 -l Specifies location of the log file. This may also come from the 00054 XRDLOGDIR environmental variable. Valid only via command line. 00055 By default, error messages go to standard error. 00056 00057 -L The local root (ignored except when -R specified). 00058 00059 -N The name2name library and parms (ignored except when -R specified). 00060 00061 -p The default port number to use for the xrootd that can be used to 00062 create/maintain the name space as well as hold archived logs. The 00063 number 1095 is used bt default. 00064 00065 -q Maximum number of log records before the log is closed and archived. 00066 Specify 1 to 1024. The default if 512. 00067 00068 -R Run is stand-alone mode and recreate the name space and, perhaps, 00069 the inventory file. 00070 00071 <host> Is the hostname of the server managing the cluster name space. You 00072 may specify more than one if they are replicated. The default is to 00073 use the hosts specified via the "all.manager" directive. 00074 */ 00075 00076 /******************************************************************************/ 00077 /* i n c l u d e f i l e s */ 00078 /******************************************************************************/ 00079 00080 #include <unistd.h> 00081 #include <ctype.h> 00082 #include <errno.h> 00083 #include <signal.h> 00084 #include <stdlib.h> 00085 #include <string.h> 00086 #include <strings.h> 00087 #include <stdio.h> 00088 #include <sys/param.h> 00089 00090 #include "Xrd/XrdTrace.hh" 00091 00092 #include "XrdCns/XrdCnsConfig.hh" 00093 #include "XrdCns/XrdCnsDaemon.hh" 00094 00095 #include "XrdOuc/XrdOucStream.hh" 00096 00097 #include "XrdSys/XrdSysError.hh" 00098 #include "XrdSys/XrdSysHeaders.hh" 00099 #include "XrdSys/XrdSysLogger.hh" 00100 #include "XrdSys/XrdSysPthread.hh" 00101 #include "XrdSys/XrdSysTimer.hh" 00102 00103 /******************************************************************************/ 00104 /* G l o b a l V a r i a b l e s */ 00105 /******************************************************************************/ 00106 00107 namespace XrdCns 00108 { 00109 extern XrdCnsConfig Config; 00110 00111 extern XrdCnsDaemon XrdCnsd; 00112 00113 XrdSysError MLog(0,"Cns_"); 00114 00115 XrdOucTrace XrdTrace(&MLog); 00116 } 00117 00118 /******************************************************************************/ 00119 /* E x t e r n a l T h r e a d I n t e r f a c e s */ 00120 /******************************************************************************/ 00121 00122 namespace XrdCns 00123 { 00124 void *MLogWorker(void *parg) 00125 { 00126 time_t midnite = XrdSysTimer::Midnight() + 86400; 00127 00128 // Just blab out the midnight herald 00129 // 00130 while(1) 00131 {XrdSysTimer::Wait(midnite - time(0)); 00132 MLog.Say(0, "XrdCnsd - Cluster Name Space Daemon"); 00133 midnite += 86400; 00134 } 00135 return (void *)0; 00136 } 00137 } 00138 using namespace XrdCns; 00139 00140 /******************************************************************************/ 00141 /* m a i n */ 00142 /******************************************************************************/ 00143 00144 int main(int argc, char *argv[]) 00145 { 00146 XrdSysLogger MLogger; 00147 XrdOucStream stdinEvents; // STDIN fed events 00148 sigset_t myset; 00149 char *xrdLogD = 0; 00150 00151 // Establish message routing 00152 // 00153 MLog.logger(&MLogger); 00154 00155 // Turn off sigpipe and host a variety of others before we start any threads 00156 // 00157 signal(SIGPIPE, SIG_IGN); // Solaris optimization 00158 sigemptyset(&myset); 00159 sigaddset(&myset, SIGPIPE); 00160 sigaddset(&myset, SIGCHLD); 00161 pthread_sigmask(SIG_BLOCK, &myset, NULL); 00162 00163 // Set the default stack size here 00164 // 00165 if (sizeof(long) > 4) XrdSysThread::setStackSize((size_t)1048576); 00166 else XrdSysThread::setStackSize((size_t)786432); 00167 00168 // Process the options and arguments 00169 // 00170 if (!Config.Configure(argc, argv)) exit(1); 00171 00172 // Construct the logfile path and bind it 00173 // 00174 if (Config.logfn || (xrdLogD = getenv("XRDLOGDIR"))) 00175 {pthread_t tid; 00176 char buff[2048]; 00177 int retc; 00178 if (Config.logfn) strcpy(buff, Config.logfn); 00179 else {strcpy(buff, xrdLogD); strcat(buff, "cnsdlog");} 00180 if (Config.logKeep) MLogger.setKeep(Config.logKeep); 00181 MLogger.Bind(buff, 24*60*60); 00182 MLog.logger(&MLogger); 00183 if ((retc = XrdSysThread::Run(&tid, MLogWorker, (void *)0, 00184 XRDSYSTHREAD_BIND, "Midnight runner"))) 00185 MLog.Emsg("Main", retc, "create midnight runner"); 00186 } 00187 00188 // Complete configuration. We do it this way so that we can easily run this 00189 // either as a plug-in or as a command. 00190 // 00191 if (!Config.Configure()) _exit(1); 00192 00193 // At this point we should be able to accept new requests 00194 // 00195 stdinEvents.Attach(STDIN_FILENO, 32*1024); 00196 XrdCnsd.getEvents(stdinEvents, "xrootd"); 00197 00198 // We should never get here 00199 // 00200 _exit(8); 00201 }