SM checks if other SM processes are running. ED macros improved a bit.
[u/mrichter/AliRoot.git] / MONITOR / alistoragemanager / alistorage.cxx
1 #include "AliStorageClientThread.h"
2 #include "AliStorageServerThread.h"
3
4 #include <TThread.h>
5 #include <iostream>
6 #include <string.h>
7 #include <sstream>
8 #include <cstdlib>
9
10 using namespace std;
11
12 void *ClientThreadHandle(void*)
13 {
14         cout<<"ALICE Storage Manager -- Starting client thread"<<endl;
15         AliStorageClientThread *client = new AliStorageClientThread();
16         if(client){delete client;}
17         return 0;
18 }
19
20 void *ServerThreadHandle(void*)
21 {
22         cout<<"\nALICE Storage Manager -- Starting server thread"<<endl;
23         AliStorageServerThread *server = new AliStorageServerThread();
24         if(server){delete server;}
25         return 0;
26 }
27
28 bool isStorageRunning()
29 {
30  // check if there is events server already running
31   const char *pid = gSystem->GetFromPipe("pidof alistorage").Data();
32   int pidSize = gSystem->GetFromPipe("pidof alistorage").Sizeof();
33   std::string pidOfAll(pid,pidSize);
34   std::stringstream pidStream(pidOfAll);
35   int word_count=0; 
36   std::string word;
37   while( pidStream >> word ) ++word_count;
38   if(word_count != 1){return true;}
39   return false;
40 }
41
42 int main()
43 {
44   if(isStorageRunning())
45     {
46       std::cout<<"There is other Storage Manager running on this machine.\n Cannot start multiple managers on the same machine. Quitting..."<<std::endl;
47       return 0;
48     }
49
50
51         TThread *clientThread = new TThread("clientThread", ClientThreadHandle,NULL);
52         TThread *serverThread = new TThread("serverThread", ServerThreadHandle,NULL);
53     
54         clientThread->Run();
55         serverThread->Run();
56         
57         clientThread->Join();
58         serverThread->Kill();//if client thread if finished, server thread is killed
59         return 0;
60 }