65 |
65 |
int main(int argc, char **argv)
|
66 |
66 |
{
|
67 |
67 |
RankScheduler * ss;
|
68 |
|
int port = 2633;
|
69 |
68 |
time_t timer= 30;
|
|
69 |
unsigned int port = 2633;
|
70 |
70 |
unsigned int machines_limit = 300;
|
71 |
71 |
unsigned int dispatch_limit = 30;
|
72 |
72 |
unsigned int host_dispatch_limit = 1;
|
|
73 |
unsigned int foreground = 0;
|
73 |
74 |
char opt;
|
|
75 |
char *pidfile_name = NULL;
|
74 |
76 |
|
75 |
|
ostringstream oss;
|
|
77 |
ofstream pidfile;
|
|
78 |
ostringstream oss;
|
76 |
79 |
|
77 |
|
while((opt = getopt(argc,argv,"p:t:m:d:h:")) != -1)
|
|
80 |
while((opt = getopt(argc,argv,"fP:p:t:m:d:h:")) != -1)
|
78 |
81 |
{
|
79 |
82 |
switch(opt)
|
80 |
83 |
{
|
|
84 |
case 'f':
|
|
85 |
foreground = 1;
|
|
86 |
break;
|
|
87 |
case 'P':
|
|
88 |
pidfile_name = strdup(optarg);
|
|
89 |
break;
|
81 |
90 |
case 'p':
|
82 |
91 |
port = atoi(optarg);
|
83 |
92 |
break;
|
... | ... | |
94 |
103 |
host_dispatch_limit = atoi(optarg);
|
95 |
104 |
break;
|
96 |
105 |
default:
|
97 |
|
cerr << "usage: " << argv[0] << " [-p port] [-t timer] ";
|
|
106 |
cerr << "usage: " << argv[0] << " [ -f ] [ -P pidfile ] [-p port] [-t timer] ";
|
98 |
107 |
cerr << "[-m machines limit] [-d dispatch limit] [-h host_dispatch_limit]\n";
|
99 |
108 |
exit(-1);
|
100 |
109 |
break;
|
... | ... | |
103 |
112 |
|
104 |
113 |
/* ---------------------------------------------------------------------- */
|
105 |
114 |
|
|
115 |
if (! foreground) {
|
|
116 |
pid_t pid, sid;
|
|
117 |
|
|
118 |
/* Fork off the parent process */
|
|
119 |
pid = fork();
|
|
120 |
if (pid < 0) {
|
|
121 |
cerr << "fork() failed.\n";
|
|
122 |
exit(1);
|
|
123 |
}
|
|
124 |
/* If we got a good PID, then
|
|
125 |
we can exit the parent process. */
|
|
126 |
if (pid > 0) {
|
|
127 |
exit(0);
|
|
128 |
}
|
|
129 |
|
|
130 |
if (pidfile_name) {
|
|
131 |
pid = getpid();
|
|
132 |
pidfile.open(pidfile_name);
|
|
133 |
|
|
134 |
if (! pidfile.is_open()) {
|
|
135 |
cerr << "failed to write pid file.\n";
|
|
136 |
exit(1);
|
|
137 |
}
|
|
138 |
pidfile << pid << "\n";
|
|
139 |
pidfile.close();
|
|
140 |
}
|
|
141 |
|
|
142 |
/* Change the file mode mask */
|
|
143 |
umask(0);
|
|
144 |
|
|
145 |
/* Create a new SID for the child process */
|
|
146 |
sid = setsid();
|
|
147 |
if (sid < 0) {
|
|
148 |
/* Log the failure */
|
|
149 |
cerr << "setsid() failed.\n";
|
|
150 |
exit(1);
|
|
151 |
}
|
|
152 |
|
|
153 |
/* Change the current working directory */
|
|
154 |
if ((chdir("/")) < 0) {
|
|
155 |
/* Log the failure */
|
|
156 |
cerr << "chdir() failed.\n";
|
|
157 |
exit(1);
|
|
158 |
}
|
|
159 |
|
|
160 |
/* Close out the standard file descriptors */
|
|
161 |
close(0);
|
|
162 |
close(1);
|
|
163 |
close(2);
|
|
164 |
}
|
|
165 |
|
|
166 |
/* ---------------------------------------------------------------------- */
|
|
167 |
|
106 |
168 |
oss << "http://localhost:" << port << "/RPC2";
|
107 |
169 |
|
108 |
170 |
ss = new RankScheduler(oss.str(),
|
109 |
|
-
|