mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2023-10-10 13:36:59 +02:00
auto generation of initial config file (#271)
* - remove feature of using multiple config files for automaticly start other hyperion instances - add auto config file creation - tune service files * add auto path creation for initial default config * debian package: rename service to hyperiond remove copy of config file
This commit is contained in:
parent
ebbb6b9440
commit
48d8781cdf
@ -1,2 +0,0 @@
|
||||
#!/bin/sh
|
||||
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/storage/hyperion/bin /storage/hyperion/bin/hyperiond "$@"
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
@ -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 "-----------------------------------------------------------------------------"
|
||||
|
@ -1,9 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <QString>
|
||||
|
||||
namespace FileUtils {
|
||||
|
||||
std::string getBaseName( std::string sourceFile);
|
||||
QString getBaseName( QString sourceFile);
|
||||
QString getDirName( QString sourceFile);
|
||||
|
||||
};
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
|
||||
|
@ -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 )
|
||||
|
@ -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
|
||||
{
|
||||
|
@ -20,6 +20,7 @@
|
||||
#include "HyperionConfig.h"
|
||||
|
||||
#include <utils/Logger.h>
|
||||
#include <utils/FileUtils.h>
|
||||
#include <webconfig/WebConfig.h>
|
||||
#include <commandline/Parser.h>
|
||||
#include <commandline/IntOption.h>
|
||||
@ -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 <options ...> [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 <options ...> 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)
|
||||
|
Loading…
Reference in New Issue
Block a user