Skip to content
Permalink
Browse files

Merge pull request #34434 from elpaso/server-standalone-small-enhance…

…ments

Server standalone: fix DISPLAY check + minor rewording of help texts
  • Loading branch information
elpaso committed Feb 14, 2020
2 parents 51ba7e8 + 76c13bc commit 9b03adaab0910a5914268c69c863e052be7a489b
Showing with 14 additions and 5 deletions.
  1. +14 −5 src/server/qgis_mapserver.cpp
@@ -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
@@ -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" ) );

@@ -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().
@@ -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" );

0 comments on commit 9b03ada

Please sign in to comment.
You can’t perform that action at this time.