Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix service test #75

Merged
merged 1 commit into from
Mar 18, 2024
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
32 changes: 26 additions & 6 deletions service.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,13 @@ def status(pid_file):
return pid


def start(pid_file, port_number, settings, log_file=None):
def start(pid_file, port_number, listen_address, settings, log_file=None):
"""
Start the service.

:param str pid_file: Full path to the pid file used by the service.
:param int port_number: The port number for the web app to listen on.
:param int listen_address: The IPv4 address that the server binds to.
:param str settings: Full path to settings file for the web app.
:param str log_file: An optional log file to use for the daemon output. By
default the daemon uses a syslog handler.
Expand All @@ -87,7 +88,9 @@ def start_wep_app():
try:
import webapp

webapp.run_server(port=port_number, settings=settings)
webapp.run_server(
port=port_number, listen_address=listen_address, settings=settings
)
except Exception as e:
logger.exception(e)
logger.warning("bye")
Expand Down Expand Up @@ -143,10 +146,19 @@ def main():
help="Full path to a file where to write the process pid.",
)
parser.add_argument(
"--log_file", help="Full path to a file where to log output.",
"--log_file",
help="Full path to a file where to log output.",
)
parser.add_argument(
"--port", type=int, default=9090, help="The port number to listen on.",
"--port",
type=int,
default=9090,
help="The port number to listen on.",
)
parser.add_argument(
"--listen_address",
default="127.0.0.1",
help="The IPv4 address that the server binds to. Use 0.0.0.0 to bind on all network interfaces.",
)
parser.add_argument("--settings", help="Full path to settings file.", required=True)
parser.add_argument(
Expand All @@ -158,7 +170,11 @@ def main():

if args.action == "start":
start(
args.pid_file, args.port, os.path.abspath(args.settings), args.log_file,
args.pid_file,
args.port,
args.listen_address,
os.path.abspath(args.settings),
args.log_file,
)
elif args.action == "stop":
stop(args.pid_file)
Expand All @@ -171,7 +187,11 @@ def main():
elif args.action == "restart":
stop(args.pid_file)
start(
args.pid_file, args.port, os.path.abspath(args.settings), args.log_file,
args.pid_file,
args.port,
args.listen_address,
os.path.abspath(args.settings),
args.log_file,
)


Expand Down
1 change: 1 addition & 0 deletions tests/test_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ def test_service_start_stop(self):
args=(
pid_f.name,
9090,
"localhost",
os.path.join(self._fixtures_path, "settings.py"),
),
)
Expand Down