~qpfiffer/logproj

a6251cffb19e63f991aeb1f6ea036be26443abe3 — Quinlan Pfiffer 3 years ago 3a1ae82 v0.1
v0.1

* Include init file
* Include chdir support to be in the right place for deployment.
* Add install to Makefile.
3 files changed, 30 insertions(+), 3 deletions(-)

M Makefile
A logproj.init
M src/main.c
M Makefile => Makefile +11 -2
@@ 1,9 1,13 @@
CFLAGS=-Werror -Wextra -Wall -O0 -g3
CFLAGS?=-Werror -Wextra -Wall -O0 -g3
INCLUDES=-pthread -I/usr/local/include/ -I./include/ `pkg-config --cflags libpq`
LIBS=-lrt -l38moths -ljwt -lscrypt -lm `pkg-config --libs libpq`
NAME=logproj
COMMON_OBJ=utils.o db.o blue_midnight_wish.o parson.o api_views.o views.o models.o

DESTDIR?=
PREFIX?=/usr/local
INSTALL_BIN=$(DESTDIR)$(PREFIX)/sbin


all: $(NAME)



@@ 15,4 19,9 @@ clean:
	$(CC) $(CFLAGS) $(LIB_INCLUDES) $(INCLUDES) -c $<

$(NAME): $(COMMON_OBJ) main.o
	$(CC) $(CLAGS) $(LIB_INCLUDES) $(INCLUDES) -o $(NAME) $^ $(LIBS)
	$(CC) $(CFLAGS) $(LIB_INCLUDES) $(INCLUDES) -o $(NAME) $^ $(LIBS)

install: all
	@mkdir -p $(INSTALL_BIN)
	@install $(NAME) $(INSTALL_BIN)
	@echo "logproj installed to $(DESTDIR)$(PREFIX) :^)."

A logproj.init => logproj.init +9 -0
@@ 0,0 1,9 @@
#!/sbin/openrc-run
command="/usr/local/sbin/logproj"
command_args="-c /srv/logproj"
supervisor="supervise-daemon"

depend() {
    use net
    provide logproj
}

M src/main.c => src/main.c +10 -1
@@ 42,7 42,7 @@ static const m38_route all_routes[] = {

static m38_app logproj_app = {
	.main_sock_fd = &main_sock_fd,
	.port = 8666,
	.port = 8667,
	.num_threads = 2,
	.routes = all_routes,
	.num_routes = sizeof(all_routes)/sizeof(all_routes[0]),


@@ 64,6 64,15 @@ int main(int argc, char *argv[]) {
				m38_log_msg(LOG_ERR, "Not enough arguments to -d.");
				return -1;
			}
		} else if (strncmp(cur_arg, "-c", strlen("-c")) == 0) {
			if ((i + 1) < argc) {
				const char *chdir_dest = argv[++i];
				m38_log_msg(LOG_INFO, "Changing directory to %s", chdir_dest);
				chdir(chdir_dest);
			} else {
				m38_log_msg(LOG_ERR, "Not enough arguments to -c.");
				return -1;
			}
		}
	}