Skip to content
Permalink
Browse files

Add debian-based setup for local test server

  • Loading branch information
dakcarto committed Feb 26, 2014
1 parent 4059c8f commit 7b2640da1b0546a31327dff75586e44c8b5a6d58
@@ -68,6 +68,7 @@ def __init__(self):
self._process = None
""":type : subprocess.Popen"""
self._win = self._mac = self._linux = self._unix = False
self._dist = ()
self._resolve_platform()

# noinspection PyMethodMayBeStatic
@@ -156,6 +157,7 @@ def _resolve_platform(self):
self._mac = s.startswith('dar')
self._unix = self._linux or self._mac
self._win = s.startswith('win')
self._dist = platform.dist()


class WebServerProcess(ServerProcess):
@@ -167,15 +169,25 @@ def __init__(self, kind, exe, conf_dir, temp_dir):
conf = os.path.join(conf_dir, 'lighttpd', 'config',
'lighttpd_{0}.conf'.format(sufx))
self.set_startenv({'QGIS_SERVER_TEMP_DIR': temp_dir})
init_scr_dir = os.path.join(conf_dir, 'lighttpd', 'scripts')
if self._mac:
init_scr = os.path.join(conf_dir, 'lighttpd', 'scripts',
'lighttpd_mac.sh')
init_scr = os.path.join(init_scr_dir, 'lighttpd_mac.sh')
self.set_startcmd([init_scr, 'start', exe, conf, temp_dir])
self.set_stopcmd([init_scr, 'stop'])
self.set_restartcmd([init_scr, 'restart', exe, conf, temp_dir])
self.set_statuscmd([init_scr, 'status'])
elif self._linux:
pass
dist = self._dist[0].lower()
if dist == 'debian' or dist == 'ubuntu':
init_scr = os.path.join(init_scr_dir, 'lighttpd_debian.sh')
self.set_startcmd([
init_scr, 'start', exe, temp_dir, conf])
self.set_stopcmd([init_scr, 'stop', exe, temp_dir])
self.set_restartcmd([
init_scr, 'restart', exe, temp_dir, conf])
self.set_statuscmd([init_scr, 'status', exe, temp_dir])
elif dist == 'fedora' or dist == 'rhel': # are these correct?
pass
else: # win
pass

@@ -188,20 +200,33 @@ def __init__(self, kind, exe, fcgi_bin, conf_dir, temp_dir):
if self._unix:
fcgi_sock = os.path.join(temp_dir, 'var', 'run',
'qgs_mapserv.sock')
init_scr_dir = os.path.join(conf_dir, 'fcgi', 'scripts')
self.set_startenv({
'QGIS_LOG_FILE':
os.path.join(temp_dir, 'log', 'qgis_server.log')})
if self._mac:
self.set_startenv({
'QGIS_LOG_FILE':
'{0}/log/qgis_server.log'.format(temp_dir)})
init_scr = os.path.join(conf_dir, 'fcgi', 'scripts',
'spawn_fcgi_mac.sh')
init_scr = os.path.join(init_scr_dir, 'spawn_fcgi_mac.sh')
self.set_startcmd([init_scr, 'start', exe, fcgi_sock,
temp_dir + fcgi_bin, temp_dir])
self.set_stopcmd([init_scr, 'stop'])
self.set_restartcmd([init_scr, 'restart', exe, fcgi_sock,
temp_dir + fcgi_bin, temp_dir])
self.set_statuscmd([init_scr, 'status'])
else: # linux
pass
elif self._linux:
dist = self._dist[0].lower()
if dist == 'debian' or dist == 'ubuntu':
init_scr = os.path.join(init_scr_dir,
'spawn_fcgi_debian.sh')
self.set_startcmd([
init_scr, 'start', exe, fcgi_sock, temp_dir])
self.set_stopcmd([
init_scr, 'stop', exe, fcgi_sock, temp_dir])
self.set_restartcmd([
init_scr, 'restart', exe, fcgi_sock, temp_dir])
self.set_statuscmd([
init_scr, 'status', exe, fcgi_sock, temp_dir])
elif dist == 'fedora' or dist == 'rhel':
pass
else: # win
pass

@@ -312,8 +337,7 @@ def web_dir(self):
return self._web_dir

def open_web_dir(self):
if os.path.exists(self._web_dir):
subprocess.call(['open', self._web_dir])
self._open_fs_item(self._web_dir)

def web_dir_install(self, items, src_dir=''):
msg = 'Items parameter should be passed in as a list'
@@ -349,19 +373,7 @@ def temp_dir(self):
return self._temp_dir

def open_temp_dir(self):
if not os.path.exists(self._temp_dir):
return
s = platform.system().lower()
if s.startswith('dar'):
subprocess.call(['open', self._temp_dir])
elif s.startswith('lin'):
# xdg-open "$1" &> /dev/null &
subprocess.call(['xdg-open', self._temp_dir,
'&>', '/dev/null', '&'])
elif s.startswith('win'):
subprocess.call([self._temp_dir])
else: # ?
pass
self._open_fs_item(self._temp_dir)

def remove_temp_dir(self):
if os.path.exists(self._temp_dir):
@@ -581,6 +593,20 @@ def _exe_path(exe):
return exe_path
return ''

@staticmethod
def _open_fs_item(item):
if not os.path.exists(item):
return
s = platform.system().lower()
if s.startswith('dar'):
subprocess.call(['open', item])
elif s.startswith('lin'):
# xdg-open "$1" &> /dev/null &
subprocess.call(['xdg-open', item])
elif s.startswith('win'):
subprocess.call([item])
else: # ?
pass

# noinspection PyPep8Naming
def getLocalServer():
@@ -735,13 +761,24 @@ def tearDown(self):
if __name__ == '__main__':
# NOTE: see test_qgis_local_server.py for CTest suite

# this is a symlink to <build dir>/output/bin/qgis_mapserv.fcgi
# (because <build dir> is not known, unless this is imported to ctest)
fcgibin = '/opt/qgis_mapserv/qgis_mapserv.fcgi'
local_srv = QgisLocalServer(fcgibin)
import argparse
parser = argparse.ArgumentParser()
parser.add_argument(
'fcgi', metavar='fcgi-bin-path',
help='Path to qgis_mapserv.fcgi'
)
args = parser.parse_args()

fcgi = os.path.realpath(args.fcgi)
if not os.path.isabs(fcgi) or not os.path.exists(fcgi):
print 'qgis_mapserv.fcgi not resolved to existing absolute path.'
sys.exit(1)

local_srv = QgisLocalServer(fcgi)
proj_dir = os.path.join(local_srv.config_dir(), 'test-project')
local_srv.web_dir_install(os.listdir(proj_dir), proj_dir)
# local_srv.open_web_dir()
# local_srv.open_temp_dir()
# sys.exit()
# creating crs needs app instance to access /resources/srs.db
# crs = QgsCoordinateReferenceSystem()
# default for labeling test data sources: WGS 84 / UTM zone 13N
@@ -769,7 +806,12 @@ def tearDown(self):
'IgnoreGetMapUrl': '1'
}

local_srv.startup(True)
# local_srv.web_server_process().start()
# openInBrowserTab('http://127.0.0.1:8448')
# local_srv.web_server_process().stop()
# sys.exit()
local_srv.startup(False)
openInBrowserTab('http://127.0.0.1:8448')
try:
local_srv.check_server_capabilities()
# open resultant png with system
@@ -0,0 +1,61 @@
#!/bin/sh
#culled from lighttpd init script


PATH=/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=$2
NAME=spawn-fcgi
DESC="$NAME"
TEMPDIR=$4
FCGI=qgis_mapserv
PIDFILE=$TEMPDIR/var/$NAME.pid
FCGISOCKET=$3
FCGIBIN=$TEMPDIR/cgi-bin/$FCGI.fcgi
SCRIPTNAME=$NAME


test -x $DAEMON || exit 1

set -e

. /lib/lsb/init-functions

case "$1" in
start)
log_daemon_msg "Starting $DESC" $NAME
if ! start-stop-daemon --start --oknodo --quiet \
--pidfile $PIDFILE -m -b --exec $DAEMON -- \
-n -C 0 -s $FCGISOCKET -f $FCGIBIN
then
log_end_msg 1
else
log_end_msg 0
fi
;;
stop)
log_daemon_msg "Stopping $DESC" $NAME
# this would also kill any other qgis_mapserv.fcgi running; not good
#if killall --signal 2 $FCGI.fcgi > /dev/null 2> /dev/null
# we can get around this because there should only be 1 process when testing
if kill -s 9 $(cat $PIDFILE) > /dev/null 2> /dev/null
then
rm -f $PIDFILE $FCGISOCKET
log_end_msg 0
else
log_end_msg 1
fi
;;
restart)
$0 stop $2 $3 $4
$0 start $2 $3 $4
;;
status)
status_of_proc -p "$PIDFILE" "$DAEMON" spawn-fcgi && exit 0 || exit $?
;;
*)
echo "Usage: $SCRIPTNAME {start|stop|restart|status}" >&2
exit 1
;;
esac

exit 0
@@ -0,0 +1,93 @@
#!/bin/sh
#from init script


PATH=/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=$2
NAME=lighttpd
DESC="web server"
PIDFILE=$3/var/$NAME.pid
SCRIPTNAME=$NAME

export QGIS_SERVER_TEMP_DIR=$3

if [ ! -z $4 ]; then
DAEMON_OPTS="-f ${4}"
fi

test -x $DAEMON || exit 1

set -e

check_syntax()
{
$DAEMON -t $DAEMON_OPTS > /dev/null || exit $?
}

. /lib/lsb/init-functions

case "$1" in
start)
check_syntax
log_daemon_msg "Starting $DESC" $NAME
if ! start-stop-daemon --start --oknodo --quiet \
--pidfile $PIDFILE --exec $DAEMON -- $DAEMON_OPTS
then
log_end_msg 1
else
log_end_msg 0
fi
;;
stop)
log_daemon_msg "Stopping $DESC" $NAME
if start-stop-daemon --stop --retry 30 --oknodo --quiet \
--pidfile $PIDFILE --exec $DAEMON
then
rm -f $PIDFILE
log_end_msg 0
else
log_end_msg 1
fi
;;
reload|force-reload)
check_syntax
log_daemon_msg "Reloading $DESC configuration" $NAME
if start-stop-daemon --stop --signal INT --quiet \
--pidfile $PIDFILE --exec $DAEMON
then
rm $PIDFILE
if start-stop-daemon --start --quiet \
--pidfile $PIDFILE --exec $DAEMON -- $DAEMON_OPTS ; then
log_end_msg 0
else
log_end_msg 1
fi
else
log_end_msg 1
fi
;;
reopen-logs)
log_daemon_msg "Reopening $DESC logs" $NAME
if start-stop-daemon --stop --signal HUP --oknodo --quiet \
--pidfile $PIDFILE --exec $DAEMON
then
log_end_msg 0
else
log_end_msg 1
fi
;;
restart)
check_syntax
$0 stop $2 $3
$0 start $2 $3 $4
;;
status)
status_of_proc -p "$PIDFILE" "$DAEMON" lighttpd && exit 0 || exit $?
;;
*)
echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload|status}" >&2
exit 1
;;
esac

exit 0

0 comments on commit 7b2640d

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