diff --git a/bin/openelec/hyperiond.sh b/bin/openelec/hyperiond.sh deleted file mode 100644 index ea9909db..00000000 --- a/bin/openelec/hyperiond.sh +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/sh -LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/storage/hyperion/bin /storage/hyperion/bin/hyperiond "$@" diff --git a/bin/service/hyperion.systemd.OE.LE.sh b/bin/service/hyperion.systemd.OE.LE.sh index 6224f917..b763a107 100644 --- a/bin/service/hyperion.systemd.OE.LE.sh +++ b/bin/service/hyperion.systemd.OE.LE.sh @@ -1,10 +1,14 @@ [Unit] Description=Hyperion ambient light systemd service for OpenELEC/LibreELEC/RasPlex After=graphical.target +After=network.target [Service] -ExecStart=/bin/sh -c "exec sh /storage/hyperion/bin/hyperiond.sh /storage/.config/hyperion/hyperion.config.json" -TimeoutStopSec=2 +WorkingDirectory=/storage/hyperion/bin/ +Environment=LD_LIBRARY_PATH=$LD_LIBRARY_PATH:. +ExecStart=./hyperiond /storage/.config/hyperion/hyperion.config.json +TimeoutStopSec=5 +KillMode=mixed Restart=always RestartSec=2 diff --git a/bin/service/hyperion.systemd.sh b/bin/service/hyperion.systemd.sh index 23faaf20..aa5b1224 100644 --- a/bin/service/hyperion.systemd.sh +++ b/bin/service/hyperion.systemd.sh @@ -1,15 +1,13 @@ [Unit] Description=Hyperion ambient light systemd service +After=network.target [Service] -Type=simple -User=hyperion -Group=hyperion ExecStart=/usr/bin/hyperiond /etc/hyperion/hyperion.config.json -ExecReload=/bin/kill -HUP $MAINPID -TimeoutStopSec=2 +TimeoutStopSec=5 +KillMode=mixed Restart=always RestartSec=2 - + [Install] WantedBy=multi-user.target diff --git a/cmake/debian/postinst b/cmake/debian/postinst index 7431bb5c..ff2a59e0 100644 --- a/cmake/debian/postinst +++ b/cmake/debian/postinst @@ -21,12 +21,6 @@ echo "--- hyperion ambient light postinstall ---" echo "- install configuration template" mkdir -p /etc/hyperion -if [ ! -e "/etc/hyperion/hyperion.config.json" ] -then - echo "install default config to /etc/hyperion" - /usr/bin/hyperiond --export-config /etc/hyperion/hyperion.config.json -fi - HYPERION_RUNNING=false pgrep hyperiond > /dev/null 2>&1 && HYPERION_RUNNING=true @@ -39,30 +33,30 @@ then echo "- init deamon: systemd" # systemd $HYPERION_RUNNING && systemctl stop hyperion 2> /dev/null - install_file /usr/share/hyperion/service/hyperion.systemd.sh /etc/systemd/system/hyperion.service || SERVICE_POSTFIX=".new" - systemctl -q enable hyperion.service + install_file /usr/share/hyperion/service/hyperion.systemd.sh /etc/systemd/system/hyperiond.service || SERVICE_POSTFIX=".new" + systemctl -q enable hyperiond.service start_msg="systemctl start hyperion" - $HYPERION_RUNNING && systemctl start hyperion + $HYPERION_RUNNING && systemctl start hyperiond elif [ -e /sbin/initctl ] then echo "- init deamon: upstart" # upstart - $HYPERION_RUNNING && initctl stop hyperion - install_file /usr/share/hyperion/service/hyperion.initctl.sh /etc/init/hyperion.conf || SERVICE_POSTFIX=".new" + $HYPERION_RUNNING && initctl stop hyperiond + install_file /usr/share/hyperion/service/hyperiond.initctl.sh /etc/init/hyperion.conf || SERVICE_POSTFIX=".new" initctl reload-configuration start_msg="initctl start hyperion" - $HYPERION_RUNNING && initctl start hyperion + $HYPERION_RUNNING && initctl start hyperiond else echo "- init deamon: sysV" # sysV - $HYPERION_RUNNING && service hyperion stop 2>/dev/null - install_file /usr/share/hyperion/service/hyperion.init.sh /etc/init.d/hyperion || SERVICE_POSTFIX=".new" - chmod +x /etc/init.d/hyperion - update-rc.d hyperion defaults 98 02 + $HYPERION_RUNNING && service hyperiond stop 2>/dev/null + install_file /usr/share/hyperion/service/hyperion.init.sh /etc/init.d/hyperiond || SERVICE_POSTFIX=".new" + chmod +x /etc/init.d/hyperiond + update-rc.d hyperiond defaults 98 02 start_msg="service hyperion start" - $HYPERION_RUNNING && service hyperion start + $HYPERION_RUNNING && service hyperiond start fi echo "-----------------------------------------------------------------------------" diff --git a/include/utils/FileUtils.h b/include/utils/FileUtils.h index bda77bc4..06122a5c 100644 --- a/include/utils/FileUtils.h +++ b/include/utils/FileUtils.h @@ -1,9 +1,10 @@ #pragma once -#include +#include namespace FileUtils { -std::string getBaseName( std::string sourceFile); +QString getBaseName( QString sourceFile); +QString getDirName( QString sourceFile); }; diff --git a/libsrc/utils/FileUtils.cpp b/libsrc/utils/FileUtils.cpp index b0f142a2..398abe5d 100644 --- a/libsrc/utils/FileUtils.cpp +++ b/libsrc/utils/FileUtils.cpp @@ -4,10 +4,16 @@ namespace FileUtils { -std::string getBaseName( std::string sourceFile) +QString getBaseName( QString sourceFile) { - QFileInfo fi( sourceFile.c_str() ); - return fi.fileName().toStdString(); + QFileInfo fi( sourceFile ); + return fi.fileName(); +} + +QString getDirName( QString sourceFile) +{ + QFileInfo fi( sourceFile ); + return fi.path(); } diff --git a/libsrc/utils/Logger.cpp b/libsrc/utils/Logger.cpp index 7fe003de..d4f05823 100644 --- a/libsrc/utils/Logger.cpp +++ b/libsrc/utils/Logger.cpp @@ -126,16 +126,16 @@ void Logger::Message(LogLevel level, const char* sourceFile, const char* func, u vsnprintf (msg, max_msg_length, fmt, args); va_end (args); - std::string location; - std::string function(func); + QString location; + QString function(func); if ( level == Logger::DEBUG ) { - location = "<" + FileUtils::getBaseName(sourceFile) + ":" + QString::number(line).toStdString()+":"+ function + "()> "; + location = "<" + FileUtils::getBaseName(sourceFile) + ":" + QString::number(line)+":"+ function + "()> "; } std::cout << "[" << _appname << " " << _name << "] <" - << LogLevelStrings[level] << "> " << location << msg + << LogLevelStrings[level] << "> " << location.toStdString() << msg << std::endl; if ( _syslogEnabled && level >= Logger::WARNING ) diff --git a/libsrc/utils/Profiler.cpp b/libsrc/utils/Profiler.cpp index 7f4773c0..e3393082 100644 --- a/libsrc/utils/Profiler.cpp +++ b/libsrc/utils/Profiler.cpp @@ -62,7 +62,7 @@ void Profiler::TimerStart(const std::string timerName, const char* sourceFile, c else { _logger->Message(Logger::DEBUG, sourceFile, func, line, "ERROR timer '%s' started in multiple locations. First occurence %s:%d:%s()", - timerName.c_str(), FileUtils::getBaseName(ret.first->second.sourceFile).c_str(), ret.first->second.line, ret.first->second.func ); + timerName.c_str(), FileUtils::getBaseName(ret.first->second.sourceFile).toLocal8Bit().constData(), ret.first->second.line, ret.first->second.func ); } } else @@ -79,7 +79,7 @@ void Profiler::TimerGetTime(const std::string timerName, const char* sourceFile, if (ret != GlobalProfilerMap.end()) { _logger->Message(Logger::DEBUG, sourceFile, func, line, "timer '%s' started at %s:%d:%s() took %f s execution time until here", timerName.c_str(), - FileUtils::getBaseName(ret->second.sourceFile).c_str(), ret->second.line, ret->second.func, getClockDelta(ret->second.startTime) ); + FileUtils::getBaseName(ret->second.sourceFile).toLocal8Bit().constData(), ret->second.line, ret->second.func, getClockDelta(ret->second.startTime) ); } else { diff --git a/src/hyperiond/main.cpp b/src/hyperiond/main.cpp index 11e13df7..3150da09 100644 --- a/src/hyperiond/main.cpp +++ b/src/hyperiond/main.cpp @@ -20,6 +20,7 @@ #include "HyperionConfig.h" #include +#include #include #include #include @@ -118,18 +119,6 @@ int main(int argc, char** argv) return 0; } - if (parser.isSet(exportConfigOption)) - { - Q_INIT_RESOURCE(resource); - if (QFile::copy(":/hyperion_default.config",exportConfigOption.value(parser))) - { - Info(log, "export complete."); - return 0; - } - Error(log, "can not export to %s",exportConfigOption.getCString(parser)); - return 1; - } - if (parser.isSet(exportEfxOption)) { Q_INIT_RESOURCE(EffectEngine); @@ -163,15 +152,46 @@ int main(int argc, char** argv) Error(log, "can not export to %s",exportEfxOption.getCString(parser)); return 1; } + - - - if (configFiles.size() == 0) + bool exportDefaultConfig = false; + bool exitAfterexportDefaultConfig = false; + QString exportConfigFileTarget; + if (parser.isSet(exportConfigOption)) { - Error(log, "Missing required configuration file. Usage: hyperiond [config.file ...]"); - return 1; + exportDefaultConfig = true; + exitAfterexportDefaultConfig = true; + exportConfigFileTarget = exportConfigOption.value(parser); + } + else if ( configFiles.size() > 0 && ! QFile::exists(configFiles[0]) ) + { + exportDefaultConfig = true; + exportConfigFileTarget = configFiles[0]; + Warning(log, "Your configuration file does not exist. hyperion writes default config"); + } + + if (exportDefaultConfig) + { + Q_INIT_RESOURCE(resource); + QDir().mkpath(FileUtils::getDirName(exportConfigFileTarget)); + if (QFile::copy(":/hyperion_default.config",exportConfigFileTarget)) + { + Info(log, "export complete."); + if (exitAfterexportDefaultConfig) return 0; + } + Error(log, "can not export to %s",exportConfigFileTarget.toLocal8Bit().constData()); + if (exitAfterexportDefaultConfig) return 1; } + if (configFiles.size() == 0) + { + Error(log, "Missing required configuration file. Usage: hyperiond config.file"); + return 1; + } + if (configFiles.size() > 1) + { + Warning(log, "You provided more than one config file. Hyperion will use only the first one"); + } int parentPid = parser.value(parentOption).toInt(); if (parentPid > 0 ) @@ -182,25 +202,10 @@ int main(int argc, char** argv) #endif } - int argvId = -1; - for(int idx=0; idx < configFiles.size(); idx++) { - if ( QFile::exists(configFiles[idx])) - { - if (argvId < 0) argvId=idx; - else startNewHyperion(getpid(), argv[0], configFiles[idx].toStdString()); - } - } - - if ( argvId < 0) - { - Warning(log, "No valid config found"); - return 1; - } - HyperionDaemon* hyperiond = nullptr; try { - hyperiond = new HyperionDaemon(configFiles[argvId], &app); + hyperiond = new HyperionDaemon(configFiles[0], &app); hyperiond->run(); } catch (std::exception& e)