Skip to content

Commit

Permalink
Fix DISPLAY check + minor rewording of help texts
Browse files Browse the repository at this point in the history
  • Loading branch information
elpaso committed Feb 12, 2020
1 parent 0fd99f3 commit 76c13bc
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/server/qgis_mapserver.cpp
Expand Up @@ -6,6 +6,9 @@ The server listens to localhost:8000, the address and port can be changed with t
environment variable QGIS_SERVER_ADDRESS and QGIS_SERVER_PORT or passing <address>:<port>
on the command line.
All requests and application messages are printed to the standard output,
while QGIS server internal logging is printed to stderr.
-------------------
begin : Jan 17 2020
copyright : (C) 2020by Alessandro Pasotti
Expand Down Expand Up @@ -88,14 +91,14 @@ int main( int argc, char *argv[] )
// minimal, minimalegl, offscreen, wayland-egl, wayland, xcb.
// https://www.ics.com/blog/qt-tips-and-tricks-part-1
// http://doc.qt.io/qt-5/qpa.html
const char *display = qgetenv( "DISPLAY" );
const QString display { qgetenv( "DISPLAY" ) };
bool withDisplay = true;
if ( !display )
if ( display.isEmpty() )
{
withDisplay = false;
qputenv( "QT_QPA_PLATFORM", "offscreen" );
QgsMessageLog::logMessage( "DISPLAY not set, running in offscreen mode, all printing capabilities will not be available.", "Server", Qgis::Info );
}

// since version 3.0 QgsServer now needs a qApp so initialize QgsApplication
QgsApplication app( argc, argv, withDisplay, QString(), QStringLiteral( "QGIS Development Server" ) );

Expand All @@ -104,6 +107,12 @@ int main( int argc, char *argv[] )
QCoreApplication::setApplicationName( "QGIS Development Server" );
QCoreApplication::setApplicationVersion( "1.0" );

if ( ! withDisplay )
{
QgsMessageLog::logMessage( "DISPLAY environment variable is not set, running in offscreen mode, all printing capabilities will not be available.\n"
"Consider installing an X server like 'xvfb' and export DISPLAY to the actual display value.", "Server", Qgis::Warning );
}

#ifdef Q_OS_WIN
// Initialize font database before fcgi_accept.
// When using FCGI with IIS, environment variables (QT_QPA_FONTDIR in this case) are lost after fcgi_accept().
Expand All @@ -130,10 +139,10 @@ int main( int argc, char *argv[] )
parser.addHelpOption();
parser.addVersionOption();
parser.addPositionalArgument( QStringLiteral( "addressAndPort" ),
QObject::tr( "Listen to address and port (default: \"localhost:8000\")\n"
QObject::tr( "Address and port (default: \"localhost:8000\")\n"
"address and port can also be specified with the environment\n"
"variables QGIS_SERVER_ADDRESS and QGIS_SERVER_PORT." ), QStringLiteral( "[address:port]" ) );
QCommandLineOption logLevelOption( "l", QObject::tr( "Sets log level (default: 0)\n"
QCommandLineOption logLevelOption( "l", QObject::tr( "Log level (default: 0)\n"
"0: INFO\n"
"1: WARNING\n"
"2: CRITICAL" ), "logLevel", "0" );
Expand Down

0 comments on commit 76c13bc

Please sign in to comment.