Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion planemo/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def global_config(self):
"""
if self._global_config is None:
self._global_config = read_global_config(self.planemo_config)
return self._global_config
return self._global_config or {}

def log(self, msg, *args):
"""Log a message to stderr."""
Expand Down
1 change: 1 addition & 0 deletions planemo/commands/cmd_shed_serve.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
@options.shed_read_options()
@options.galaxy_run_options()
@options.galaxy_config_options()
@options.pid_file_option()
@click.option(
"--skip_dependencies",
is_flag=True,
Expand Down
3 changes: 2 additions & 1 deletion planemo/galaxy/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,7 @@ def config_join(*args):
env["GALAXY_TEST_UPLOAD_ASYNC"] = "false"
env["GALAXY_TEST_LOGGING_CONFIG"] = config_join("logging.ini")
env["GALAXY_DEVELOPMENT_ENVIRONMENT"] = "1"
env["GALAXY_SKIP_CLIENT_BUILD"] = "1"
web_config = _sub(WEB_SERVER_CONFIG_TEMPLATE, template_args)
write_file(config_join("galaxy.ini"), web_config)
tool_conf_contents = _sub(TOOL_CONF_TEMPLATE, template_args)
Expand Down Expand Up @@ -850,7 +851,7 @@ def startup_command(self, ctx, **kwds):
run_script += " --daemon"
self.env["GALAXY_RUN_ALL"] = "1"
else:
run_script += " --server-name '%s' --reload" % self.server_name
run_script += " --server-name '%s'" % self.server_name
server_ini = os.path.join(self.config_directory, "galaxy.ini")
self.env["GALAXY_CONFIG_FILE"] = server_ini
cd_to_galaxy_command = "cd %s" % self.galaxy_root
Expand Down
7 changes: 7 additions & 0 deletions planemo/galaxy/serve.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from __future__ import print_function

import contextlib
import os
import time

from planemo import io
Expand Down Expand Up @@ -59,6 +60,12 @@ def _serve(ctx, runnables, **kwds):
ctx.vlog("Waiting for service on (%s, %s)" % (host, port))
assert network_util.wait_http_service(galaxy_url)
config.install_workflows()
if kwds.get("pid_file"):
real_pid_file = config.pid_file
if os.path.exists(config.pid_file):
os.symlink(real_pid_file, kwds["pid_file"])
else:
io.warn("Can't find Galaxy pid file [%s] to link" % real_pid_file)
return config


Expand Down
12 changes: 7 additions & 5 deletions planemo/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from __future__ import print_function

import contextlib
import errno
import fnmatch
import os
import shutil
Expand Down Expand Up @@ -171,13 +172,14 @@ def ps1_for_path(path, base="PS1"):


def kill_pid_file(pid_file):
if not os.path.exists(pid_file):
print("No pid file...")
return
try:
os.stat(pid_file)
except OSError as e:
if e.errno == errno.ENOENT:
return False

pid = int(open(pid_file, "r").read())
killed = kill_posix(pid)
print("killed? %s" % killed)
kill_posix(pid)


def kill_posix(pid):
Expand Down
12 changes: 7 additions & 5 deletions planemo/network_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@ def wait_net_service(server, port, timeout=None):

port = int(port)

s = socket.socket()
# Following line prevents this method from interfering with process
# it is waiting for on localhost.
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
if timeout:
end = now() + timeout

while True:
s = socket.socket()
# Following line prevents this method from interfering with process
# it is waiting for on localhost.
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
try:
if timeout:
next_timeout = end - now()
Expand All @@ -68,7 +68,9 @@ def wait_net_service(server, port, timeout=None):
return False

except socket.error:
pass
# if getattr(e, "errno") == 61:
# refused_connections += 1
s.close()
else:
s.close()
return True
15 changes: 15 additions & 0 deletions planemo/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -968,6 +968,20 @@ def galaxy_target_options():
)


def pid_file_option():
pid_file_type = click.Path(
file_okay=True,
dir_okay=False,
resolve_path=True,
)
return planemo_option(
"--pid_file",
type=pid_file_type,
default=None,
help="Location of pid file is executed with --daemon."
)


def daemon_option():
return planemo_option(
"--daemon",
Expand All @@ -993,6 +1007,7 @@ def galaxy_serve_options():
docker_galaxy_image_option(),
galaxy_config_options(),
daemon_option(),
pid_file_option(),
)


Expand Down
9 changes: 5 additions & 4 deletions tests/test_cmd_serve.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ def test_serve_daemon(self):
user_gi = self._user_gi
assert len(user_gi.histories.get_histories(name=TEST_HISTORY_NAME)) == 0
user_gi.histories.create_history(TEST_HISTORY_NAME)
kill_pid_file(self._pid_file)

@skip_if_environ("PLANEMO_SKIP_GALAXY_TESTS")
def test_serve_workflow(self):
Expand Down Expand Up @@ -97,12 +98,12 @@ def _launch_thread_and_wait(self, func, args=[]):
t = threading.Thread(target=target)
t.daemon = True
t.start()
time.sleep(10)
assert network_util.wait_net_service("127.0.0.1", port)
time.sleep(5)
assert network_util.wait_net_service("127.0.0.1", port, timeout=600)
time.sleep(1)
assert network_util.wait_net_service("127.0.0.1", port)
assert network_util.wait_net_service("127.0.0.1", port, timeout=600)
time.sleep(1)
assert network_util.wait_net_service("127.0.0.1", port)
assert network_util.wait_net_service("127.0.0.1", port, timeout=600)

def _run(self, serve_args=[]):
test_cmd = [
Expand Down
9 changes: 8 additions & 1 deletion tests/test_galaxy_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,14 @@
import os

from planemo.galaxy.config import galaxy_config
from .test_utils import TempDirectoryContext, test_context
from .test_utils import (
skip_if_environ,
TempDirectoryContext,
test_context,
)


@skip_if_environ("PLANEMO_SKIP_GALAXY_TESTS")
def test_defaults():
"""Test by default Galaxy files are stored in temp ``config_directory``."""
with _test_galaxy_config() as config:
Expand All @@ -15,13 +20,15 @@ def test_defaults():
_assert_property_is(config, "database_connection", conn)


@skip_if_environ("PLANEMO_SKIP_GALAXY_TESTS")
def test_database_connection_override_path():
"""Test by default Galaxy files are stored in temp ``config_directory``."""
conn = "postgresql://username:password@localhost/mydatabase"
with _test_galaxy_config(database_connection=conn) as config:
_assert_property_is(config, "database_connection", conn)


@skip_if_environ("PLANEMO_SKIP_GALAXY_TESTS")
def test_override_files_path():
"""Test Galaxy file path overrideable with --file_path."""
with TempDirectoryContext() as tdc:
Expand Down