From fc34bbb27000894c741202f004d6bddffaab037d Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Fri, 15 May 2015 01:16:52 +0200 Subject: renamed nopsyncd to nopfetchd diff --git a/.gitignore b/.gitignore index dbc5999..963d785 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,5 @@ src/include.mk -src/nopsyncd +src/nopfetchd src/config.h src/*.o src/*.d diff --git a/debian/rhnop-server.install b/debian/rhnop-server.install index b51dc4b..fbe4c09 100644 --- a/debian/rhnop-server.install +++ b/debian/rhnop-server.install @@ -1,6 +1,6 @@ usr/bin/noprml -usr/bin/nopsyncd -etc/rhnop/nopsyncd.conf +usr/bin/nopfetchd +etc/rhnop/nopfetchd.conf usr/share/rhnop/rddb.lua usr/share/rhnop/playlog.lua usr/share/rhnop/qlistener.lua diff --git a/debian/rhnop-server.nopfetchd.service b/debian/rhnop-server.nopfetchd.service new file mode 100644 index 0000000..efafabb --- /dev/null +++ b/debian/rhnop-server.nopfetchd.service @@ -0,0 +1,13 @@ +[Unit] +Description=Radio Helsinki Now Playing Daemon (Server) + +[Service] +ExecStart=/usr/bin/nopfetchd +Restart=on-failure +PrivateTmp=yes +PrivateDevices=yes +ProtectSystem=full +ProtectHome=yes + +[Install] +WantedBy=multi-user.target diff --git a/debian/rhnop-server.nopsyncd.service b/debian/rhnop-server.nopsyncd.service deleted file mode 100644 index 2783cca..0000000 --- a/debian/rhnop-server.nopsyncd.service +++ /dev/null @@ -1,13 +0,0 @@ -[Unit] -Description=Radio Helsinki Now Playing Daemon (Server) - -[Service] -ExecStart=/usr/bin/nopsyncd -Restart=on-failure -PrivateTmp=yes -PrivateDevices=yes -ProtectSystem=full -ProtectHome=yes - -[Install] -WantedBy=multi-user.target diff --git a/debian/rules b/debian/rules index e09f048..d82394a 100755 --- a/debian/rules +++ b/debian/rules @@ -6,7 +6,7 @@ override_dh_auto_configure: dh_auto_configure -- --ebuild-compat override_dh_systemd_enable: - dh_systemd_enable --name=nopsyncd nopsyncd.service + dh_systemd_enable --name=nopfetchd nopfetchd.service dh_systemd_enable --name=nopsysstated nopsysstated.service dh_systemd_enable --name=nopcollectd-master nopcollectd-master.service dh_systemd_enable --name=nopcollectd-standby nopcollectd-standby.service diff --git a/src/Makefile b/src/Makefile index 5dce506..b478018 100644 --- a/src/Makefile +++ b/src/Makefile @@ -23,10 +23,10 @@ ifneq ($(MAKECMDGOALS),distclean) include include.mk endif -EXECUTABLE := nopsyncd +EXECUTABLE := nopfetchd C_OBJS := l_pipe.o \ - nopsyncd.o + nopfetchd.o C_SRCS := $(C_OBJS:%.o=%.c) @@ -93,7 +93,7 @@ install-lib: install-etc: $(INSTALL) -d $(DESTDIR)$(ETCDIR)/rhnop - $(INSTALL) -m 640 nopsyncd.conf $(DESTDIR)$(ETCDIR)/rhnop + $(INSTALL) -m 640 nopfetchd.conf $(DESTDIR)$(ETCDIR)/rhnop $(INSTALL) -m 640 nopcollectd.*.conf $(DESTDIR)$(ETCDIR)/rhnop $(INSTALL) -m 640 nopsysstated.conf $(DESTDIR)$(ETCDIR)/rhnop diff --git a/src/configure b/src/configure index 43df410..ccd63ac 100755 --- a/src/configure +++ b/src/configure @@ -237,15 +237,15 @@ EOF cat > config.h <. */ -#ifndef NOPSYNCD_l_pipe_h_INCLUDED -#define NOPSYNCD_l_pipe_h_INCLUDED +#ifndef NOPFETCHD_l_pipe_h_INCLUDED +#define NOPFETCHD_l_pipe_h_INCLUDED #include diff --git a/src/nopcollectd b/src/nopcollectd index d2d635c..d02e6f0 100755 --- a/src/nopcollectd +++ b/src/nopcollectd @@ -19,11 +19,6 @@ -- You should have received a copy of the GNU General Public License -- along with rhnop. If not, see . -- --- --- send now and next cart# and length to nopsyncd --- this script should be called by the now/next macro cart --- the arguments should be: now# nowlen next# nextlen --- socket = require "socket" diff --git a/src/nopfetchd.c b/src/nopfetchd.c new file mode 100644 index 0000000..9791020 --- /dev/null +++ b/src/nopfetchd.c @@ -0,0 +1,196 @@ +/* + * rhnop + * + * Copyright (C) 2011-2015 Christian Pointner + * + * This file is part of rhnop. + * + * rhnop is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * rhnop is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with rhnop. If not, see . + */ + +#include +#include +#include +#include +#include + +#include +#include +#include + +#include "l_pipe.h" +#include "config.h" + +#define LUA_MAIN_LOOP_FUNC "main_loop" +#define QLISTENER DATAROOTDIR"/rhnop/qlistener.lua" +#define TCPSERVER DATAROOTDIR"/rhnop/tcpserver.lua" + +#if LUA_VERSION_NUM > 501 +static const luaL_Reg nopfetchd_lualibs[] = { + {"_G", luaopen_base}, + {LUA_LOADLIBNAME, luaopen_package}, + {LUA_TABLIBNAME, luaopen_table}, + {LUA_STRLIBNAME, luaopen_string}, + {LUA_MATHLIBNAME, luaopen_math}, + {LUA_IOLIBNAME, luaopen_io}, + {LUA_OSLIBNAME, luaopen_os}, + {LUA_BITLIBNAME, luaopen_bit32}, + {LUA_PIPELIBNAME, luaopen_pipe}, + {NULL, NULL} +}; +#else +static const luaL_Reg nopfetchd_lualibs[] = { + {"", luaopen_base}, + {LUA_LOADLIBNAME, luaopen_package}, + {LUA_TABLIBNAME, luaopen_table}, + {LUA_STRLIBNAME, luaopen_string}, + {LUA_MATHLIBNAME, luaopen_math}, + {LUA_IOLIBNAME, luaopen_io}, + {LUA_OSLIBNAME, luaopen_os}, + {LUA_PIPELIBNAME, luaopen_pipe}, + {NULL, NULL} +}; +#endif + +int init_main_loop(lua_State *L, const char* filename) +{ + const luaL_Reg *lib = nopfetchd_lualibs; + +#if LUA_VERSION_NUM > 501 + for (; lib->func; lib++) { + luaL_requiref(L, lib->name, lib->func, 1); + lua_pop(L, 1); + } +#else + for (; lib->func; lib++) { + lua_pushcfunction(L, lib->func); + lua_pushstring(L, lib->name); + lua_call(L, 1, 0); + } +#endif + + int ret = luaL_loadfile(L, filename); + if(ret) { + const char* err_str = luaL_checkstring(L, -1); + switch(ret) { + case LUA_ERRSYNTAX: fprintf(stderr, "luaL_loadfile() syntax error: %s\n", err_str); break; + case LUA_ERRMEM: fprintf(stderr, "luaL_loadfile() malloc error: %s\n", err_str); break; + case LUA_ERRFILE: fprintf(stderr, "lauL_loadfile() error: %s\n", err_str); break; + default: fprintf(stderr, "luaL_loadfile() unknown error: %s\n", err_str); break; + } + return -1; + } + + lua_pushstring(L, DATAROOTDIR"/rhnop"); + lua_setglobal(L, "rhnoplibdir"); + lua_pushstring(L, ETCDIR"/rhnop"); + lua_setglobal(L, "rhnopescdir"); + + ret = lua_pcall(L, 0, 0, 0); + if(ret) { + const char* err_str = luaL_checkstring(L, -1); + switch(ret) { + case LUA_ERRRUN: fprintf(stderr, "lua_pcall() runtime error: %s\n", err_str); break; + case LUA_ERRMEM: fprintf(stderr, "lua_pcall() malloc error: %s\n", err_str); break; + case LUA_ERRERR: fprintf(stderr, "lua_pcall() error at error handler function: %s\n", err_str); break; + } + return -1; + } + + return 0; +} + +int call_main_loop(lua_State* L, const char* filename) +{ + lua_getglobal(L, LUA_MAIN_LOOP_FUNC); + if(!lua_isfunction(L, -1)) { + fprintf(stderr, "there is no function '%s' at file '%s'\n", LUA_MAIN_LOOP_FUNC, filename); + return -1; + }; + + int ret = lua_pcall(L, 0, 1, 0); + if(ret) { + const char* err_str = luaL_checkstring(L, -1); + switch(ret) { + case LUA_ERRRUN: fprintf(stderr, "lua_pcall(%s:%s) runtime error: %s\n", filename, LUA_MAIN_LOOP_FUNC, err_str); break; + case LUA_ERRMEM: fprintf(stderr, "lua_pcall(%s:%s) malloc error: %s\n", filename, LUA_MAIN_LOOP_FUNC, err_str); break; + case LUA_ERRERR: fprintf(stderr, "lua_pcall(%s:%s) error at error handler function: %s\n", filename, LUA_MAIN_LOOP_FUNC, err_str); break; + } + return -1; + } + + ret = lua_tointeger(L, 1); + return ret; +} + +void* main_loop(void* file) +{ + if(!file) + pthread_exit(NULL); + + + lua_State *L; + L = luaL_newstate(); + if(!L) { + fprintf(stderr, "error creating lua state\n"); + pthread_exit(NULL); + } + + int ret = init_main_loop(L, (char*)file); + if(!ret) + ret = call_main_loop(L, (char*)file); + + printf("%s returned with %d\n", (char*)file, ret); + + lua_close(L); + + /* this should bring down the other thread as well + at least this is true for the tcp-server thread */ + pipe_close(); + + pthread_exit(NULL); +} + +int main(int argc, char* argv[]) +{ + printf("starting nopfetchd...\n"); + + pthread_t qlistener, tcpserver; + + int ret = pipe_init(); + if(ret) { + fprintf(stderr, "Error creating pipe: %s\n", strerror(errno)); + return 1; + } + + ret = pthread_create(&qlistener, NULL, main_loop, QLISTENER); + if(ret) { + fprintf(stderr, "Error creating qlistener thread (code: %d)\n", ret); + return 1; + } + pthread_detach(qlistener); /* can't kill this thread so don't join to it */ + + ret = pthread_create(&tcpserver, NULL, main_loop, TCPSERVER); + if(ret) { + fprintf(stderr, "Error creating tcpserver thread (code: %d)\n", ret); + return 1; + } + +/* this thread can't be cancelled so don't wait for it */ +/* pthread_join(qlistener, NULL); */ + pthread_join(tcpserver, NULL); + + printf("stopping nopfetchd.\n"); + return 0; +} diff --git a/src/nopfetchd.conf b/src/nopfetchd.conf new file mode 100644 index 0000000..a80d620 --- /dev/null +++ b/src/nopfetchd.conf @@ -0,0 +1,18 @@ +queue_name=/rhnop +tcp_host=* +tcp_port=2345 + +music_carts_lo=400000 +music_carts_hi=499999 + +rddb_db=rivendell +rddb_host=127.0.0.1 +#rddb_port=3306 +rddb_user= +rddb_pwd= + +playlog_db=rhnop +playlog_host=127.0.0.1 +#playlog_port=3306 +playlog_user= +playlog_pwd= diff --git a/src/noprml b/src/noprml index f7c696a..9f9a9d1 100755 --- a/src/noprml +++ b/src/noprml @@ -20,7 +20,7 @@ -- along with rhnop. If not, see . -- -- --- send now and next cart# and length to nopsyncd +-- send now and next cart# and length to nopfetchd -- this script should be called by the now/next macro cart -- the arguments should be: now# nowlen next# nextlen -- @@ -54,7 +54,7 @@ if q == nil then end end --- send out message to nopsyncd +-- send out message to nopfetchd local result, err = mq.send(q, timestamp .. " " .. arg[1] .. " " .. arg[2] .. " " .. arg[3] .. " " .. arg[4], 0) if result == nil then io.stderr:write("sending message failed: " .. err .. "\n") diff --git a/src/nopsyncd.c b/src/nopsyncd.c deleted file mode 100644 index c26d637..0000000 --- a/src/nopsyncd.c +++ /dev/null @@ -1,196 +0,0 @@ -/* - * rhnop - * - * Copyright (C) 2011-2015 Christian Pointner - * - * This file is part of rhnop. - * - * rhnop is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * rhnop is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with rhnop. If not, see . - */ - -#include -#include -#include -#include -#include - -#include -#include -#include - -#include "l_pipe.h" -#include "config.h" - -#define LUA_MAIN_LOOP_FUNC "main_loop" -#define QLISTENER DATAROOTDIR"/rhnop/qlistener.lua" -#define TCPSERVER DATAROOTDIR"/rhnop/tcpserver.lua" - -#if LUA_VERSION_NUM > 501 -static const luaL_Reg nopsyncd_lualibs[] = { - {"_G", luaopen_base}, - {LUA_LOADLIBNAME, luaopen_package}, - {LUA_TABLIBNAME, luaopen_table}, - {LUA_STRLIBNAME, luaopen_string}, - {LUA_MATHLIBNAME, luaopen_math}, - {LUA_IOLIBNAME, luaopen_io}, - {LUA_OSLIBNAME, luaopen_os}, - {LUA_BITLIBNAME, luaopen_bit32}, - {LUA_PIPELIBNAME, luaopen_pipe}, - {NULL, NULL} -}; -#else -static const luaL_Reg nopsyncd_lualibs[] = { - {"", luaopen_base}, - {LUA_LOADLIBNAME, luaopen_package}, - {LUA_TABLIBNAME, luaopen_table}, - {LUA_STRLIBNAME, luaopen_string}, - {LUA_MATHLIBNAME, luaopen_math}, - {LUA_IOLIBNAME, luaopen_io}, - {LUA_OSLIBNAME, luaopen_os}, - {LUA_PIPELIBNAME, luaopen_pipe}, - {NULL, NULL} -}; -#endif - -int init_main_loop(lua_State *L, const char* filename) -{ - const luaL_Reg *lib = nopsyncd_lualibs; - -#if LUA_VERSION_NUM > 501 - for (; lib->func; lib++) { - luaL_requiref(L, lib->name, lib->func, 1); - lua_pop(L, 1); - } -#else - for (; lib->func; lib++) { - lua_pushcfunction(L, lib->func); - lua_pushstring(L, lib->name); - lua_call(L, 1, 0); - } -#endif - - int ret = luaL_loadfile(L, filename); - if(ret) { - const char* err_str = luaL_checkstring(L, -1); - switch(ret) { - case LUA_ERRSYNTAX: fprintf(stderr, "luaL_loadfile() syntax error: %s\n", err_str); break; - case LUA_ERRMEM: fprintf(stderr, "luaL_loadfile() malloc error: %s\n", err_str); break; - case LUA_ERRFILE: fprintf(stderr, "lauL_loadfile() error: %s\n", err_str); break; - default: fprintf(stderr, "luaL_loadfile() unknown error: %s\n", err_str); break; - } - return -1; - } - - lua_pushstring(L, DATAROOTDIR"/rhnop"); - lua_setglobal(L, "rhnoplibdir"); - lua_pushstring(L, ETCDIR"/rhnop"); - lua_setglobal(L, "rhnopescdir"); - - ret = lua_pcall(L, 0, 0, 0); - if(ret) { - const char* err_str = luaL_checkstring(L, -1); - switch(ret) { - case LUA_ERRRUN: fprintf(stderr, "lua_pcall() runtime error: %s\n", err_str); break; - case LUA_ERRMEM: fprintf(stderr, "lua_pcall() malloc error: %s\n", err_str); break; - case LUA_ERRERR: fprintf(stderr, "lua_pcall() error at error handler function: %s\n", err_str); break; - } - return -1; - } - - return 0; -} - -int call_main_loop(lua_State* L, const char* filename) -{ - lua_getglobal(L, LUA_MAIN_LOOP_FUNC); - if(!lua_isfunction(L, -1)) { - fprintf(stderr, "there is no function '%s' at file '%s'\n", LUA_MAIN_LOOP_FUNC, filename); - return -1; - }; - - int ret = lua_pcall(L, 0, 1, 0); - if(ret) { - const char* err_str = luaL_checkstring(L, -1); - switch(ret) { - case LUA_ERRRUN: fprintf(stderr, "lua_pcall(%s:%s) runtime error: %s\n", filename, LUA_MAIN_LOOP_FUNC, err_str); break; - case LUA_ERRMEM: fprintf(stderr, "lua_pcall(%s:%s) malloc error: %s\n", filename, LUA_MAIN_LOOP_FUNC, err_str); break; - case LUA_ERRERR: fprintf(stderr, "lua_pcall(%s:%s) error at error handler function: %s\n", filename, LUA_MAIN_LOOP_FUNC, err_str); break; - } - return -1; - } - - ret = lua_tointeger(L, 1); - return ret; -} - -void* main_loop(void* file) -{ - if(!file) - pthread_exit(NULL); - - - lua_State *L; - L = luaL_newstate(); - if(!L) { - fprintf(stderr, "error creating lua state\n"); - pthread_exit(NULL); - } - - int ret = init_main_loop(L, (char*)file); - if(!ret) - ret = call_main_loop(L, (char*)file); - - printf("%s returned with %d\n", (char*)file, ret); - - lua_close(L); - - /* this should bring down the other thread as well - at least this is true for the tcp-server thread */ - pipe_close(); - - pthread_exit(NULL); -} - -int main(int argc, char* argv[]) -{ - printf("starting nopsyncd...\n"); - - pthread_t qlistener, tcpserver; - - int ret = pipe_init(); - if(ret) { - fprintf(stderr, "Error creating pipe: %s\n", strerror(errno)); - return 1; - } - - ret = pthread_create(&qlistener, NULL, main_loop, QLISTENER); - if(ret) { - fprintf(stderr, "Error creating qlistener thread (code: %d)\n", ret); - return 1; - } - pthread_detach(qlistener); /* can't kill this thread so don't join to it */ - - ret = pthread_create(&tcpserver, NULL, main_loop, TCPSERVER); - if(ret) { - fprintf(stderr, "Error creating tcpserver thread (code: %d)\n", ret); - return 1; - } - -/* this thread can't be cancelled so don't wait for it */ -/* pthread_join(qlistener, NULL); */ - pthread_join(tcpserver, NULL); - - printf("stopping nopsyncd.\n"); - return 0; -} diff --git a/src/nopsyncd.conf b/src/nopsyncd.conf deleted file mode 100644 index a80d620..0000000 --- a/src/nopsyncd.conf +++ /dev/null @@ -1,18 +0,0 @@ -queue_name=/rhnop -tcp_host=* -tcp_port=2345 - -music_carts_lo=400000 -music_carts_hi=499999 - -rddb_db=rivendell -rddb_host=127.0.0.1 -#rddb_port=3306 -rddb_user= -rddb_pwd= - -playlog_db=rhnop -playlog_host=127.0.0.1 -#playlog_port=3306 -playlog_user= -playlog_pwd= diff --git a/src/nopsysstated b/src/nopsysstated index 36992f5..c8ed3bd 100755 --- a/src/nopsysstated +++ b/src/nopsysstated @@ -19,11 +19,6 @@ -- You should have received a copy of the GNU General Public License -- along with rhnop. If not, see . -- --- --- send now and next cart# and length to nopsyncd --- this script should be called by the now/next macro cart --- the arguments should be: now# nowlen next# nextlen --- socket = require "socket" diff --git a/src/playlog.lua b/src/playlog.lua index e692154..1dea4e9 100644 --- a/src/playlog.lua +++ b/src/playlog.lua @@ -22,7 +22,7 @@ luasql = require "luasql.mysql" -- CREATE DATABASE rhnop CHARACTER SET utf8 COLLATE utf8_unicode_ci; --- GRANT select,insert,update ON rhnop.* TO 'nopsyncd' IDENTIFIED BY ''; +-- GRANT select,insert,update ON rhnop.* TO 'nopfetchd' IDENTIFIED BY ''; -- GRANT select ON rhnop.* TO 'nopcollectd' IDENTIFIED BY ''; -- USE rhnop -- CREATE TABLE IF NOT EXISTS now (timestamp BIGINT UNSIGNED PRIMARY KEY NOT NULL, cart INT NOT NULL, len INT, showtitle VARCHAR(255), title VARCHAR(255), artist VARCHAR(255), album VARCHAR(255), ismusic BOOLEAN); diff --git a/src/qlistener.lua b/src/qlistener.lua index 050dfc1..0cc2d6b 100644 --- a/src/qlistener.lua +++ b/src/qlistener.lua @@ -75,7 +75,7 @@ function handle_message(msg) end function main_loop() - init(rhnopescdir .. "/nopsyncd.conf") + init(rhnopescdir .. "/nopfetchd.conf") posix.umask("rwxrwxr-x") local q, err = mq.create(cnf.queue_name, "ro", "rw-rw----") diff --git a/src/tcpserver.lua b/src/tcpserver.lua index 76c80ad..67c63fb 100644 --- a/src/tcpserver.lua +++ b/src/tcpserver.lua @@ -27,7 +27,7 @@ conf = require "conf" function init_server() local server = assert(socket.tcp()) - cnf = conf.load(rhnopescdir .. "/nopsyncd.conf") + cnf = conf.load(rhnopescdir .. "/nopfetchd.conf") assert(server:setoption('reuseaddr', true)) assert(server:bind(cnf.tcp_host, cnf.tcp_port)) assert(server:listen(5)) -- cgit v0.10.2