-
Notifications
You must be signed in to change notification settings - Fork 0
/
genarcuslocalconf.c
54 lines (47 loc) · 1.73 KB
/
genarcuslocalconf.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
static char *local_hostname = "localhost";
static char *local_ip = "127.0.0.1";
int main(int argc, char **argv)
{
char filenam[128];
char svccode[128];
char content[128];
FILE *fp;
int start; /* start port number */
int count; /* node count */
int i, rc;
if (argc != 3) {
fprintf(stderr, "Usage) genarcuslocalconf <port> <count>\n");
return -1;
}
start = atoi(argv[1]);
count = atoi(argv[2]);
sprintf(svccode, "%dnode", count);
sprintf(filenam, "./local.%s.json", svccode);
fp = fopen(filenam, "w");
assert(fp);
sprintf(content, "{\n");
rc = fputs(content, fp); assert(rc != 0);
sprintf(content, "\t\"serviceCode\": \"%s\",\n", svccode);
rc = fputs(content, fp); assert(rc != 0);
sprintf(content, "\t\"servers\": [\n");
rc = fputs(content, fp); assert(rc != 0);
for (i = 0; i < (count-1); i++) {
sprintf(content, "\t\t{ \"hostname\": \"%s\", \"ip\": \"%s\", \"config\": { \"port\": \"%d\" } },\n",
local_hostname, local_ip, start+i);
rc = fputs(content, fp); assert(rc != 0);
}
sprintf(content, "\t\t{ \"hostname\": \"%s\", \"ip\": \"%s\", \"config\": { \"port\": \"%d\" } }\n",
local_hostname, local_ip, start+i);
rc = fputs(content, fp); assert(rc != 0);
sprintf(content, "\t],\n");
rc = fputs(content, fp); assert(rc != 0);
sprintf(content, "\t\"config\": { \"threads\" : \"1\", \"memlimit\" : \"10\", \"connections\" : \"10\"}\n");
rc = fputs(content, fp); assert(rc != 0);
sprintf(content, "}\n");
rc = fputs(content, fp); assert(rc != 0);
fclose(fp);
return 0;
}