Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
itminedu
agkyra
Commits
459eb515
Commit
459eb515
authored
Jun 05, 2015
by
Giorgos Korfiatis
Browse files
Exec server script in forked process
parent
fcb933e6
Changes
4
Hide whitespace changes
Inline
Side-by-side
agkyra/gui.py
View file @
459eb515
...
...
@@ -14,7 +14,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from
ws4py.client
import
WebSocketBaseClient
from
agkyra.protocol
import
SessionHelper
from
agkyra.protocol
import
SessionHelper
,
launch_server
from
agkyra.config
import
AGKYRA_DIR
import
subprocess
import
os
...
...
@@ -81,9 +81,7 @@ class GUI(WebSocketBaseClient):
def
run
():
"""Prepare SessionHelper and GUI and run them in the proper order"""
LOG
.
info
(
'Start SessionHelper session'
)
subprocess
.
Popen
([
'agkyra-cli'
,
'launch_server'
])
launch_server
()
LOG
.
info
(
'Client blocks until session is ready'
)
session
=
SessionHelper
().
wait_session_to_load
()
assert
session
,
'UI server failed to load...'
...
...
agkyra/protocol.py
View file @
459eb515
...
...
@@ -31,6 +31,8 @@ from agkyra.syncer import (
from
agkyra.config
import
AgkyraConfig
,
AGKYRA_DIR
CURPATH
=
os
.
path
.
dirname
(
os
.
path
.
abspath
(
__file__
))
LOG
=
logging
.
getLogger
(
__name__
)
SYNCERS
=
utils
.
ThreadSafeDict
()
...
...
@@ -528,3 +530,12 @@ class WebSocketProtocol(WebSocket):
self
.
send_json
({
'INTERNAL ERROR'
:
500
})
LOG
.
error
(
'EXCEPTION: %s'
%
e
)
self
.
terminate
()
def
launch_server
():
"""Launch the server in a separate process"""
LOG
.
info
(
'Start SessionHelper session'
)
pid
=
os
.
fork
()
if
not
pid
:
server_path
=
os
.
path
.
join
(
CURPATH
,
'scripts'
,
'server.py'
)
os
.
execlp
(
"python"
,
"python"
,
server_path
)
agkyra/scripts/cli.py
View file @
459eb515
...
...
@@ -40,19 +40,7 @@ LOGGER.setLevel(logging.DEBUG)
def
main
():
from
agkyra.cli
import
AgkyraCLI
from
sys
import
argv
if
sys
.
argv
[
1
]
in
(
'launch_server'
,
):
# This piece of code will stay here until the CLI can launch a server
# by itself
from
agkyra.protocol
import
SessionHelper
LOGGER
.
debug
(
'Start the session helper'
)
helper
=
SessionHelper
()
if
not
helper
.
load_active_session
():
helper
.
create_session
()
helper
.
server
.
serve_forever
()
else
:
LOGGER
.
info
(
'Another session is running, aborting'
)
else
:
AgkyraCLI
().
onecmd
(
' '
.
join
(
argv
[
1
:]
or
[
'help'
,
]))
AgkyraCLI
().
onecmd
(
' '
.
join
(
argv
[
1
:]
or
[
'help'
,
]))
if
__name__
==
"__main__"
:
...
...
agkyra/scripts/server.py
0 → 100644
View file @
459eb515
# Copyright (C) 2015 GRNET S.A.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import
os
from
agkyra
import
config
AGKYRA_DIR
=
config
.
AGKYRA_DIR
import
logging
LOGFILE
=
os
.
path
.
join
(
AGKYRA_DIR
,
'agkyra.log'
)
LOGGER
=
logging
.
getLogger
(
'agkyra'
)
HANDLER
=
logging
.
FileHandler
(
LOGFILE
)
FORMATTER
=
logging
.
Formatter
(
"%(name)s %(levelname)s:%(asctime)s:%(message)s"
)
HANDLER
.
setFormatter
(
FORMATTER
)
LOGGER
.
addHandler
(
HANDLER
)
LOGGER
.
setLevel
(
logging
.
INFO
)
def
main
():
from
agkyra.protocol
import
SessionHelper
LOGGER
.
debug
(
'Start the session helper'
)
helper
=
SessionHelper
()
if
not
helper
.
load_active_session
():
helper
.
create_session
()
helper
.
server
.
serve_forever
()
else
:
LOGGER
.
info
(
'Another session is running, aborting'
)
exit
(
1
)
if
__name__
==
"__main__"
:
main
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment