new --initialize option for recorder

closes #45
This commit is contained in:
Jan-Piet Mens
2015-09-30 10:51:58 +02:00
parent 3cee00dbd7
commit cb0c5038c2
3 changed files with 67 additions and 13 deletions
+10 -12
View File
@@ -66,19 +66,19 @@ ot-recorder: recorder.o $(OTR_OBJS)
ocat: ocat.o $(OTR_OBJS)
$(CC) $(CFLAGS) -o ocat ocat.o $(OTR_OBJS) $(LIBS)
$(OTR_OBJS): config.mk
$(OTR_OBJS): config.mk Makefile
recorder.o: recorder.c storage.h util.h Makefile geo.h udata.h json.h http.h gcache.h config.mk hooks.h
geo.o: geo.h geo.c udata.h Makefile config.mk
geohash.o: geohash.h geohash.c udata.h Makefile config.mk
geo.o: geo.h geo.c udata.h
geohash.o: geohash.h geohash.c udata.h
base64.o: base64.h base64.c
gcache.o: gcache.c gcache.h json.h config.mk
misc.o: misc.c misc.h udata.h Makefile config.mk
http.o: http.c mongoose.h util.h http.h storage.h config.mk
util.o: util.c util.h Makefile config.mk
gcache.o: gcache.c gcache.h json.h
misc.o: misc.c misc.h udata.h
http.o: http.c mongoose.h util.h http.h storage.h
util.o: util.c util.h
mongoose.o: mongoose.c mongoose.h
ocat.o: ocat.c storage.h util.h config.mk version.h
storage.o: storage.c storage.h util.h gcache.h config.mk
ocat.o: ocat.c storage.h util.h version.h
storage.o: storage.c storage.h util.h gcache.h
hooks.o: hooks.c udata.h hooks.h util.h version.h gcache.h
@@ -93,12 +93,10 @@ mdb/liblmdb.a:
install: ot-recorder ocat
mkdir -p $(DESTDIR)$(INSTALLDIR)/bin
mkdir -p $(DESTDIR)$(INSTALLDIR)/sbin
mkdir -p $(DESTDIR)$(STORAGEDEFAULT)/ghash
mkdir -p $(DESTDIR)$(DOCROOT)
cp -R docroot/* $(DESTDIR)$(DOCROOT)/
install -m 0755 ot-recorder $(DESTDIR)$(INSTALLDIR)/sbin
install -m 0755 ocat $(DESTDIR)$(INSTALLDIR)/bin
$(DESTDIR)$(INSTALLDIR)/bin/ocat --load=topic2tid < /dev/null
$(DESTDIR)$(INSTALLDIR)/bin/ocat --load=luadb < /dev/null
$(DESTDIR)$(INSTALLDIR)/sbin/ot-recorder --initialize
# mkdir -p $(DESTDIR)/etc/systemd/system/
# install --mode 0644 etc/ot-recorder.service $(DESTDIR)/etc/systemd/system/ot-recorder.service
+6
View File
@@ -230,6 +230,12 @@ Obtain and download the software, either [as a package, if available](https://pa
Type `make` and watch the fun. When that finishes, you should have at least two executable programs called `ot-recorder` which is the _recorder_ proper, and `ocat`. If you want you can install these using `make install`, but this is not necessary: the programs will run from whichever directory you like if you add `--doc-root ./docroot` to the _recorder_ options.
Ensure the LMDB databases are initialized by running the following command which is safe to do, also after an upgrade. (This initialization is non-destructive -- it will not delete any data.)
```
ot-recorder --initialize
```
Unless already provided by the package you installed, we recommend you create a shell script with which you hence-force launch the _recorder_. Note that you can have it subscribe to multiple topics, and you can launch sundry instances of the recorder (e.g. for distinct brokers) as long as you ensure:
* that each instance uses a distinct `--storage`
+51 -1
View File
@@ -741,6 +741,7 @@ void usage(char *prog)
printf(" --port -p MQTT port (1883)\n");
printf(" --logfacility syslog facility (local0)\n");
printf(" --quiet disable printing of messages to stdout\n");
printf(" --initialize initialize storage\n");
#ifdef WITH_HTTP
printf(" --http-host <host> HTTP addr to bind to (localhost)\n");
printf(" --http-port <port> -A HTTP port (8083); 0 to disable HTTP\n");
@@ -777,7 +778,7 @@ int main(int argc, char **argv)
char *luascript = NULL;
#endif
int port = 1883;
int rc, i, ch, hosted = FALSE;
int rc, i, ch, hosted = FALSE, initialize = FALSE;
static struct udata udata, *ud = &udata;
struct utsname uts;
UT_string *clientid;
@@ -843,6 +844,7 @@ int main(int argc, char **argv)
{ "precision", required_argument, 0, 5},
{ "hosted", no_argument, 0, 6},
{ "quiet", no_argument, 0, 8},
{ "initialize", no_argument, 0, 9},
#ifdef WITH_LUA
{ "lua-script", required_argument, 0, 7},
#endif
@@ -860,6 +862,9 @@ int main(int argc, char **argv)
break;
switch (ch) {
case 9:
initialize = TRUE;
break;
case 8:
ud->verbose = FALSE;
break;
@@ -929,6 +934,51 @@ int main(int argc, char **argv)
}
/*
* If requested to, attempt to create ghash storage and
* initialize (non-destructively -- just open for write)
* the LMDB databases.
*/
if (initialize == TRUE) {
struct gcache *gt;
char path[BUFSIZ], *pp;
snprintf(path, BUFSIZ, "%s/ghash", STORAGEDIR);
if (!is_directory(path)) {
pp = strdup(path);
if (mkpath(pp) < 0) {
fprintf(stderr, "Cannot mkdir %s: %s", path, strerror(errno));
exit(2);
}
free(pp);
}
#ifdef WITH_LMDB
if ((gt = gcache_open(path, NULL, FALSE)) == NULL) {
fprintf(stderr, "Cannot lmdb-open MainDB\n");
exit(2);
}
gcache_close(gt);
if ((gt = gcache_open(path, "topic2tid", FALSE)) == NULL) {
fprintf(stderr, "Cannot lmdb-open `topic2tid'\n");
exit(2);
}
gcache_close(gt);
#ifdef WITH_LUA
if ((gt = gcache_open(path, "luadb", FALSE)) == NULL) {
fprintf(stderr, "Cannot lmdb-open `luadb'\n");
exit(2);
}
gcache_close(gt);
#endif /* !LUA */
#endif
exit(0);
}
argc -= (optind);
argv += (optind);