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]
|
[Unit]
|
||||||
Description=Hyperion ambient light systemd service for OpenELEC/LibreELEC/RasPlex
|
Description=Hyperion ambient light systemd service for OpenELEC/LibreELEC/RasPlex
|
||||||
After=graphical.target
|
After=graphical.target
|
||||||
|
After=network.target
|
||||||
|
|
||||||
[Service]
|
[Service]
|
||||||
ExecStart=/bin/sh -c "exec sh /storage/hyperion/bin/hyperiond.sh /storage/.config/hyperion/hyperion.config.json"
|
WorkingDirectory=/storage/hyperion/bin/
|
||||||
TimeoutStopSec=2
|
Environment=LD_LIBRARY_PATH=$LD_LIBRARY_PATH:.
|
||||||
|
ExecStart=./hyperiond /storage/.config/hyperion/hyperion.config.json
|
||||||
|
TimeoutStopSec=5
|
||||||
|
KillMode=mixed
|
||||||
Restart=always
|
Restart=always
|
||||||
RestartSec=2
|
RestartSec=2
|
||||||
|
|
||||||
|
@ -1,15 +1,13 @@
|
|||||||
[Unit]
|
[Unit]
|
||||||
Description=Hyperion ambient light systemd service
|
Description=Hyperion ambient light systemd service
|
||||||
|
After=network.target
|
||||||
|
|
||||||
[Service]
|
[Service]
|
||||||
Type=simple
|
|
||||||
User=hyperion
|
|
||||||
Group=hyperion
|
|
||||||
ExecStart=/usr/bin/hyperiond /etc/hyperion/hyperion.config.json
|
ExecStart=/usr/bin/hyperiond /etc/hyperion/hyperion.config.json
|
||||||
ExecReload=/bin/kill -HUP $MAINPID
|
TimeoutStopSec=5
|
||||||
TimeoutStopSec=2
|
KillMode=mixed
|
||||||
Restart=always
|
Restart=always
|
||||||
RestartSec=2
|
RestartSec=2
|
||||||
|
|
||||||
[Install]
|
[Install]
|
||||||
WantedBy=multi-user.target
|
WantedBy=multi-user.target
|
||||||
|
@ -21,12 +21,6 @@ echo "--- hyperion ambient light postinstall ---"
|
|||||||
echo "- install configuration template"
|
echo "- install configuration template"
|
||||||
mkdir -p /etc/hyperion
|
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
|
HYPERION_RUNNING=false
|
||||||
pgrep hyperiond > /dev/null 2>&1 && HYPERION_RUNNING=true
|
pgrep hyperiond > /dev/null 2>&1 && HYPERION_RUNNING=true
|
||||||
|
|
||||||
@ -39,30 +33,30 @@ then
|
|||||||
echo "- init deamon: systemd"
|
echo "- init deamon: systemd"
|
||||||
# systemd
|
# systemd
|
||||||
$HYPERION_RUNNING && systemctl stop hyperion 2> /dev/null
|
$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"
|
install_file /usr/share/hyperion/service/hyperion.systemd.sh /etc/systemd/system/hyperiond.service || SERVICE_POSTFIX=".new"
|
||||||
systemctl -q enable hyperion.service
|
systemctl -q enable hyperiond.service
|
||||||
start_msg="systemctl start hyperion"
|
start_msg="systemctl start hyperion"
|
||||||
$HYPERION_RUNNING && systemctl start hyperion
|
$HYPERION_RUNNING && systemctl start hyperiond
|
||||||
|
|
||||||
elif [ -e /sbin/initctl ]
|
elif [ -e /sbin/initctl ]
|
||||||
then
|
then
|
||||||
echo "- init deamon: upstart"
|
echo "- init deamon: upstart"
|
||||||
# upstart
|
# upstart
|
||||||
$HYPERION_RUNNING && initctl stop hyperion
|
$HYPERION_RUNNING && initctl stop hyperiond
|
||||||
install_file /usr/share/hyperion/service/hyperion.initctl.sh /etc/init/hyperion.conf || SERVICE_POSTFIX=".new"
|
install_file /usr/share/hyperion/service/hyperiond.initctl.sh /etc/init/hyperion.conf || SERVICE_POSTFIX=".new"
|
||||||
initctl reload-configuration
|
initctl reload-configuration
|
||||||
start_msg="initctl start hyperion"
|
start_msg="initctl start hyperion"
|
||||||
$HYPERION_RUNNING && initctl start hyperion
|
$HYPERION_RUNNING && initctl start hyperiond
|
||||||
|
|
||||||
else
|
else
|
||||||
echo "- init deamon: sysV"
|
echo "- init deamon: sysV"
|
||||||
# sysV
|
# sysV
|
||||||
$HYPERION_RUNNING && service hyperion stop 2>/dev/null
|
$HYPERION_RUNNING && service hyperiond stop 2>/dev/null
|
||||||
install_file /usr/share/hyperion/service/hyperion.init.sh /etc/init.d/hyperion || SERVICE_POSTFIX=".new"
|
install_file /usr/share/hyperion/service/hyperion.init.sh /etc/init.d/hyperiond || SERVICE_POSTFIX=".new"
|
||||||
chmod +x /etc/init.d/hyperion
|
chmod +x /etc/init.d/hyperiond
|
||||||
update-rc.d hyperion defaults 98 02
|
update-rc.d hyperiond defaults 98 02
|
||||||
start_msg="service hyperion start"
|
start_msg="service hyperion start"
|
||||||
$HYPERION_RUNNING && service hyperion start
|
$HYPERION_RUNNING && service hyperiond start
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "-----------------------------------------------------------------------------"
|
echo "-----------------------------------------------------------------------------"
|
||||||
|
@ -1,9 +1,10 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <string>
|
#include <QString>
|
||||||
|
|
||||||
namespace FileUtils {
|
namespace FileUtils {
|
||||||
|
|
||||||
std::string getBaseName( std::string sourceFile);
|
QString getBaseName( QString sourceFile);
|
||||||
|
QString getDirName( QString sourceFile);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
@ -4,10 +4,16 @@
|
|||||||
|
|
||||||
namespace FileUtils {
|
namespace FileUtils {
|
||||||
|
|
||||||
std::string getBaseName( std::string sourceFile)
|
QString getBaseName( QString sourceFile)
|
||||||
{
|
{
|
||||||
QFileInfo fi( sourceFile.c_str() );
|
QFileInfo fi( sourceFile );
|
||||||
return fi.fileName().toStdString();
|
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);
|
vsnprintf (msg, max_msg_length, fmt, args);
|
||||||
va_end (args);
|
va_end (args);
|
||||||
|
|
||||||
std::string location;
|
QString location;
|
||||||
std::string function(func);
|
QString function(func);
|
||||||
if ( level == Logger::DEBUG )
|
if ( level == Logger::DEBUG )
|
||||||
{
|
{
|
||||||
location = "<" + FileUtils::getBaseName(sourceFile) + ":" + QString::number(line).toStdString()+":"+ function + "()> ";
|
location = "<" + FileUtils::getBaseName(sourceFile) + ":" + QString::number(line)+":"+ function + "()> ";
|
||||||
}
|
}
|
||||||
|
|
||||||
std::cout
|
std::cout
|
||||||
<< "[" << _appname << " " << _name << "] <"
|
<< "[" << _appname << " " << _name << "] <"
|
||||||
<< LogLevelStrings[level] << "> " << location << msg
|
<< LogLevelStrings[level] << "> " << location.toStdString() << msg
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
|
|
||||||
if ( _syslogEnabled && level >= Logger::WARNING )
|
if ( _syslogEnabled && level >= Logger::WARNING )
|
||||||
|
@ -62,7 +62,7 @@ void Profiler::TimerStart(const std::string timerName, const char* sourceFile, c
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
_logger->Message(Logger::DEBUG, sourceFile, func, line, "ERROR timer '%s' started in multiple locations. First occurence %s:%d:%s()",
|
_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
|
else
|
||||||
@ -79,7 +79,7 @@ void Profiler::TimerGetTime(const std::string timerName, const char* sourceFile,
|
|||||||
if (ret != GlobalProfilerMap.end())
|
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(),
|
_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
|
else
|
||||||
{
|
{
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
#include "HyperionConfig.h"
|
#include "HyperionConfig.h"
|
||||||
|
|
||||||
#include <utils/Logger.h>
|
#include <utils/Logger.h>
|
||||||
|
#include <utils/FileUtils.h>
|
||||||
#include <webconfig/WebConfig.h>
|
#include <webconfig/WebConfig.h>
|
||||||
#include <commandline/Parser.h>
|
#include <commandline/Parser.h>
|
||||||
#include <commandline/IntOption.h>
|
#include <commandline/IntOption.h>
|
||||||
@ -118,18 +119,6 @@ int main(int argc, char** argv)
|
|||||||
return 0;
|
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))
|
if (parser.isSet(exportEfxOption))
|
||||||
{
|
{
|
||||||
Q_INIT_RESOURCE(EffectEngine);
|
Q_INIT_RESOURCE(EffectEngine);
|
||||||
@ -163,15 +152,46 @@ int main(int argc, char** argv)
|
|||||||
Error(log, "can not export to %s",exportEfxOption.getCString(parser));
|
Error(log, "can not export to %s",exportEfxOption.getCString(parser));
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool exportDefaultConfig = false;
|
||||||
|
bool exitAfterexportDefaultConfig = false;
|
||||||
if (configFiles.size() == 0)
|
QString exportConfigFileTarget;
|
||||||
|
if (parser.isSet(exportConfigOption))
|
||||||
{
|
{
|
||||||
Error(log, "Missing required configuration file. Usage: hyperiond <options ...> [config.file ...]");
|
exportDefaultConfig = true;
|
||||||
return 1;
|
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();
|
int parentPid = parser.value(parentOption).toInt();
|
||||||
if (parentPid > 0 )
|
if (parentPid > 0 )
|
||||||
@ -182,25 +202,10 @@ int main(int argc, char** argv)
|
|||||||
#endif
|
#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;
|
HyperionDaemon* hyperiond = nullptr;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
hyperiond = new HyperionDaemon(configFiles[argvId], &app);
|
hyperiond = new HyperionDaemon(configFiles[0], &app);
|
||||||
hyperiond->run();
|
hyperiond->run();
|
||||||
}
|
}
|
||||||
catch (std::exception& e)
|
catch (std::exception& e)
|
||||||
|
Loading…
Reference in New Issue
Block a user