52 int getDebugEnum(
const char *what);
53 Int_t getXrootdPid(
Int_t port,
const char *subdir =
"xpdtut");
54 Int_t checkXrootdAt(
Int_t port,
const char *host =
"localhost");
55 Int_t checkXproofdAt(
Int_t port,
const char *host =
"localhost");
57 Int_t killXrootdAt(
Int_t port,
const char *
id = 0);
76 const char *refloc =
"proof://localhost:40000";
83 Printf(
"getProof: this script can only be executed via ACliC:");
84 Printf(
"getProof: root [] .x <path>/getProof.C+");
85 Printf(
"getProof: or root [] .L <path>/getProof.C+");
86 Printf(
"getProof: root [] getProof(...)");
98 while (s.Tokenize(
t, from ,
" ")) {
99 if (
t.BeginsWith(
"valgrind_opts:"))
104 if (vopts.
IsNull()) vopts =
"valgrind_opts:--leak-check=full --track-origins=yes";
106 Printf(
"getProof: valgrind run: '%s' (opts: '%s')", vopt.
Data(), vopts.
Data());
111 TUrl uu(url), uref(refloc);
112 Bool_t ext = (strcmp(uu.GetHost(), uref.GetHost()) ||
113 (uu.GetPort() != uref.GetPort())) ?
kTRUE :
kFALSE;
116 if (!strcmp(url,
"lite://") || !url[0]) {
117 if (!url[0]) uu.SetUrl(
"lite://");
119 TString swrk(
"<default> workers");
121 uu.SetOptions(
Form(
"workers=%d", nwrks));
122 swrk.Form(
"%d workers", nwrks);
126 Printf(
"getProof: trying to open a PROOF-Lite session with %s", swrk.Data());
128 Printf(
"getProof: trying to open a session on the external cluster at '%s'", url);
133 if (ext && !lite && nwrks > 0) {
134 Printf(
"getProof: WARNING: started/attached a session on external cluster (%s):"
135 " 'nwrks=%d' ignored", url, nwrks);
137 if (ext && !lite &&
dir && strlen(
dir) > 0) {
138 Printf(
"getProof: WARNING: started/attached a session on external cluster (%s):"
139 " 'dir=\"%s\"' ignored", url,
dir);
141 if (ext && !strcmp(opt,
"force")) {
142 Printf(
"getProof: WARNING: started/attached a session on external cluster (%s):"
143 " 'opt=\"force\"' ignored", url);
146 Printf(
"getProof: WARNING: started/attached a session on external cluster (%s):"
147 " 'dyn=kTRUE' ignored", url);
153 Printf(
"getProof: could not get/start a valid session at %s", url);
156 Printf(
"getProof: could not get/start a valid session at %s - try resarting the daemon", url);
165 Printf(
"getProof: local PROOF not yet supported on Windows, sorry!");
177 Printf(
"getProof: unable to create the working area at the requested path: '%s'"
178 " - cannot continue", tutdir.
Data());
180 Printf(
"getProof: working area at the requested path '%s'"
181 " created but it is not writable - cannot continue", tutdir.
Data());
189 Printf(
"getProof: working area at the requested path '%s'"
190 " exists but is not writable - cannot continue", tutdir.
Data());
196 Printf(
"getProof: working area not specified temp ");
203 Printf(
"getProof: could not get user info");
209 tutdir +=
"/.getproof";
213 Printf(
"getProof: unable to get a writable working area (tried: %s)"
214 " - cannot continue", tutdir.
Data());
219 Printf(
"getProof: working area (tutorial dir): %s", tutdir.
Data());
224 datasetdir =
Form(
"%s/dataset", tutdir.
Data());
228 Printf(
"getProof: unable to get a writable dataset directory (tried: %s)"
229 " - cannot continue", datasetdir.Data());
232 Printf(
"getProof: dataset dir: %s", datasetdir.Data());
238 u.SetProtocol(
"proof");
239 if (!strcmp(uu.GetHost(), uref.GetHost()) && (uu.GetPort() != uref.GetPort()))
240 u.SetPort(uu.GetPort());
241 Int_t lportp = u.GetPort();
242 Int_t lportx = lportp + 1;
258 if ((rc = checkXproofdAt(lportp)) == 1) {
259 Printf(
"getProof: something else the a XProofd service is running on"
260 " port %d - cannot continue", lportp);
263 }
else if (rc == 0) {
267 pid = getXrootdPid(lportx);
268 Printf(
"getProof: daemon found listening on dedicated ports {%d,%d} (pid: %d)",
269 lportx, lportp, pid);
270 if (isatty(0) == 0 || isatty(1) == 0) {
274 if (!strcmp(opt,
"ask")) {
275 char *answer = (
char *) Getline(
"getProof: would you like to restart it (N,Y)? [N] ");
276 if (answer && (answer[0] ==
'Y' || answer[0] ==
'y'))
280 if (!strcmp(opt,
"force"))
286 Printf(
"getProof: cleaning existing instance ...");
288 cmd =
Form(
"kill -9 %d", pid);
290 Printf(
"getProof: problems stopping xrootd process %d (%d)", pid, rc);
292 Printf(
"getProof: wait 5 secs so that previous connections are cleaned ...");
301 Printf(
"getProof: xrootd not found: please check the environment!");
306 cmd =
Form(
"rm -fr %s/xpdtut %s %s %s %s", tutdir.
Data(), workarea.
Data(),
307 xpdcf.Data(), xpdpid.Data(), proofsessions.Data());
311 FILE *fcf = fopen(xpdcf.Data(),
"w");
313 Printf(
"getProof: could not create config file for XPD (%s)", xpdcf.Data());
316 fprintf(fcf,
"### Use admin path at %s/admin to avoid interferences with other users\n", tutdir.
Data());
317 fprintf(fcf,
"xrd.adminpath %s/admin\n", tutdir.
Data());
318 #if defined(R__MACOSX)
319 fprintf(fcf,
"### Use dedicated socket path under /tmp to avoid length problems\n");
320 fprintf(fcf,
"xpd.sockpathdir /tmp/xpd-sock\n");
322 fprintf(fcf,
"### Run data serving on port %d\n", lportp+1);
323 fprintf(fcf,
"xrd.port %d\n", lportp+1);
324 fprintf(fcf,
"### Load the XrdProofd protocol on port %d\n", lportp);
325 fprintf(fcf,
"xrd.protocol xproofd libXrdProofd.so\n");
326 fprintf(fcf,
"xpd.port %d\n", lportp);
328 fprintf(fcf,
"### Force number of local workers\n");
329 fprintf(fcf,
"xpd.localwrks %d\n", nwrks);
331 fprintf(fcf,
"### Root path for working dir\n");
332 fprintf(fcf,
"xpd.workdir %s\n", workarea.
Data());
333 fprintf(fcf,
"### Allow different users to connect\n");
334 fprintf(fcf,
"xpd.multiuser 1\n");
335 fprintf(fcf,
"### Limit the number of query results kept in the master sandbox\n");
336 fprintf(fcf,
"xpd.putrc ProofServ.UserQuotas: maxquerykept=10\n");
337 fprintf(fcf,
"### Limit the number of sessions kept in the sandbox\n");
338 fprintf(fcf,
"xpd.putrc Proof.MaxOldSessions: 1\n");
340 fprintf(fcf,
"### Use dataset directory under the tutorial dir\n");
341 fprintf(fcf,
"xpd.datasetsrc file url:%s opt:-Cq:Av:As:\n", datasetdir.Data());
344 fprintf(fcf,
"### Use dynamic, per-job scheduling\n");
345 fprintf(fcf,
"xpd.putrc Proof.DynamicStartup 1\n");
347 fprintf(fcf,
"### Local data server for the temporary output files\n");
348 fprintf(fcf,
"xpd.putenv LOCALDATASERVER=root://%s:%d\n",
gSystem->
HostName(), lportx);
350 Printf(
"getProof: xrootd config file at %s", xpdcf.Data());
353 Printf(
"getProof: xrootd log file at %s", xpdlogprt.Data());
354 cmd =
Form(
"%s -c %s -b -l %s -n xpdtut -p %d",
355 xrootd, xpdcf.Data(), xpdlog.Data(), lportx);
356 Printf(
"(NB: any error line from XrdClientSock::RecvRaw and XrdClientMessage::ReadRaw should be ignored)");
358 Printf(
"getProof: problems starting xrootd (%d)", rc);
364 Printf(
"getProof: waiting for xrootd to start ...");
367 pid = getXrootdPid(lportx);
368 Printf(
"getProof: xrootd pid: %d", pid);
371 FILE *fpid = fopen(xpdpid.Data(),
"w");
373 Printf(
"getProof: could not create pid file for XPD");
375 fprintf(fpid,
"%d\n", pid);
379 Printf(
"getProof: start / attach the PROOF session ...");
384 Printf(
"getProof: starting local session failed");
395 Int_t getXrootdPid(
Int_t port,
const char *subdir)
399 Printf(
"getXrootdPid: Xrootd/Proof not supported on Windows, sorry!");
405 const char *com =
"-eo pid,comm";
406 #elif defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__APPLE__)
407 const char *com =
"ax -w -w";
409 const char *com =
"-w -w -eo pid,command";
412 if (subdir && strlen(subdir) > 0) {
413 cmd.
Form(
"ps %s | grep xrootd | grep \"\\-p %d\" | grep %s", com, port, subdir);
415 cmd.
Form(
"ps %s | grep xrootd | grep \"\\-p %d\"", com, port);
419 char line[2048], rest[2048];
420 while (fgets(line,
sizeof(line), fp)) {
421 sscanf(line,
"%d %s", &pid, rest);
431 Int_t checkXrootdAt(
Int_t port,
const char *host)
441 if (!(s.IsValid())) {
443 Printf(
"checkXrootdAt: could not open connection to %s:%d", host, port);
448 memset(&initHS, 0,
sizeof(initHS));
451 int len =
sizeof(initHS);
452 s.SendRaw(&initHS, len);
456 int readCount = s.RecvRaw(&type, len);
457 if (readCount != len) {
459 Printf(
"checkXrootdAt: 1st: wrong number of bytes read: %d (expected: %d)",
469 readCount = s.RecvRaw(&xbody, len);
470 if (readCount != len) {
472 Printf(
"checkXrootdAt: 2nd: wrong number of bytes read: %d (expected: %d)",
477 }
else if (type == 8) {
480 Printf(
"checkXrootdAt: server is ROOTD");
485 Printf(
"checkXrootdAt: unknown server type: %d", type);
492 Int_t checkXproofdAt(
Int_t port,
const char *host)
502 if (!(s.IsValid())) {
504 Printf(
"checkXproofdAt: could not open connection to %s:%d", host, port);
509 memset(&initHS, 0,
sizeof(initHS));
510 initHS.third = (int)
host2net((
int)1);
511 int len =
sizeof(initHS);
512 s.SendRaw(&initHS, len);
517 s.SendRaw(&dum[0],
sizeof(dum));
521 int readCount = s.RecvRaw(&type, len);
522 if (readCount != len) {
524 Printf(
"checkXproofdAt: 1st: wrong number of bytes read: %d (expected: %d)",
534 readCount = s.RecvRaw(&xbody, len);
535 if (readCount != len) {
537 Printf(
"checkXproofdAt: 2nd: wrong number of bytes read: %d (expected: %d)",
541 xbody.protover =
net2host(xbody.protover);
542 xbody.msgval =
net2host(xbody.msglen);
543 xbody.msglen =
net2host(xbody.msgval);
545 }
else if (type == 8) {
548 Printf(
"checkXproofdAt: server is PROOFD");
553 Printf(
"checkXproofdAt: unknown server type: %d", type);
567 Printf(
"startXrootdAt: Xrootd not supported on Windows, sorry!");
574 if ((rc = checkXrootdAt(port)) == 1) {
576 Printf(
"startXrootdAt: some other service running on port %d - cannot proceed ", port);
579 }
else if (rc == 0) {
587 Printf(
"startXrootdAt: xrootd service already available on port %d: ", port);
588 char *answer = (
char *) Getline(
"startXrootdAt: would you like to restart it (N,Y)? [N] ");
589 if (answer && (answer[0] ==
'Y' || answer[0] ==
'y')) {
596 Printf(
"startXrootdAt: cleaning existing instance ...");
599 Int_t pid = getXrootdPid(port,
"xrd-basic");
604 Printf(
"startXrootdAt: problems stopping xrootd process %d (%d)", pid, rc);
612 Printf(
"startXrootdAt: could not assert dir for log file");
617 cmd.
Form(
"xrootd -d -p %d -b -l /tmp/xrd-basic/xrootd.log", port);
618 if (exportdirs && strlen(exportdirs) > 0) {
621 while (dirs.Tokenize(d, from,
" ")) {
630 Printf(
"startXrootdAt: problems executing starting command (%d)", rc);
634 Printf(
"startXrootdAt: waiting for xrootd to start ...");
637 if ((rc = checkXrootdAt(port)) != 0) {
638 Printf(
"startXrootdAt: xrootd service not available at %d (rc = %d) - startup failed",
642 Printf(
"startXrootdAt: basic xrootd started!");
650 Int_t killXrootdAt(
Int_t port,
const char *
id)
656 Printf(
"killXrootdAt: Xrootd not supported on Windows, sorry!");
660 Int_t pid = -1, rc= 0;
661 if ((pid = getXrootdPid(port,
id)) > 0) {
666 Printf(
"killXrootdAt: problems stopping xrootd process %d (%d)", pid, rc);
674 int getDebugEnum(
const char *what)
682 while (sws.Tokenize(sw, from ,
"|")) {
687 }
else if (sw ==
"Packetizer") {
689 }
else if (sw ==
"Loop") {
691 }
else if (sw ==
"Selector") {
693 }
else if (sw ==
"Output") {
695 }
else if (sw ==
"Input") {
697 }
else if (sw ==
"Global") {
699 }
else if (sw ==
"Package") {
701 }
else if (sw ==
"Feedback") {
703 }
else if (sw ==
"Condor") {
705 }
else if (sw ==
"Draw") {
707 }
else if (sw ==
"Asyn") {
709 }
else if (sw ==
"Cache") {
711 }
else if (sw ==
"Collect") {
713 }
else if (sw ==
"Dataset") {
715 }
else if (sw ==
"Submerger") {
717 }
else if (sw ==
"Monitoring") {
719 }
else if (sw ==
"All") {
721 }
else if (!sw.
IsNull()) {
722 Printf(
"WARNING: requested debug enum name '%s' does not exist: assuming 'All'", sw.
Data());
virtual Bool_t AccessPathName(const char *path, EAccessMode mode=kFileExists)
Returns FALSE if one can access a file using the specified access mode.
This class represents a WWW compatible URL.
virtual const char * TempDirectory() const
Return a user configured or systemwide directory to create temporary files in.
virtual char * Which(const char *search, const char *file, EAccessMode mode=kFileExists)
Find location of file in a search path.
virtual FILE * OpenPipe(const char *command, const char *mode)
Open a pipe.
Bool_t BeginsWith(const char *s, ECaseCompare cmp=kExact) const
virtual int mkdir(const char *name, Bool_t recursive=kFALSE)
Make a file system directory.
virtual void SetValue(const char *name, const char *value, EEnvLevel level=kEnvChange, const char *type=0)
Set the value of a resource or create a new resource.
const char * Data() const
UShort_t net2host(UShort_t x)
virtual void Sleep(UInt_t milliSec)
Sleep milliSec milli seconds.
virtual const char * Getenv(const char *env)
Get environment variable.
virtual UserGroup_t * GetUserInfo(Int_t uid)
Returns all user info in the UserGroup_t structure.
static TProof * Open(const char *url=0, const char *conffile=0, const char *confdir=0, Int_t loglevel=0)
Start a PROOF session on a specific cluster.
Int_t getProof(const char *where, Int_t verbose=1)
Open a PROOF session at gUrl.
Bool_t EndsWith(const char *pat, ECaseCompare cmp=kExact) const
Return true if string ends with the specified string.
R__EXTERN TSystem * gSystem
void Form(const char *fmt,...)
Formats a string using a printf style format descriptor.
char * Form(const char *fmt,...)
static void AddEnvVar(const char *name, const char *value)
Add an variable to the list of environment variables passed to proofserv on the master and slaves...
virtual Int_t Exec(const char *shellcmd)
Execute a command.
virtual int ClosePipe(FILE *pipe)
Close the pipe.
TString & Remove(Ssiz_t pos)
virtual const char * HostName()
Return the system's host name.
This class controls a Parallel ROOT Facility, PROOF, cluster.
virtual Int_t GetUid(const char *user=0)
Returns the user's id. If user = 0, returns current user's id.
UShort_t host2net(UShort_t x)