From d9f7eddd63ff8b8ec6de3498bd33b234af0a92e5 Mon Sep 17 00:00:00 2001 From: Michael Merickel Date: Thu, 12 Nov 2015 22:52:29 -0600 Subject: fix usage of --monitor-restart with --daemon Fixes #1216 --- pyramid/scripts/pserve.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/pyramid/scripts/pserve.py b/pyramid/scripts/pserve.py index 1bfedf384..63f34f6c2 100644 --- a/pyramid/scripts/pserve.py +++ b/pyramid/scripts/pserve.py @@ -302,7 +302,10 @@ class PServeCommand(object): raise ValueError(msg) writeable_pid_file.close() - if getattr(self.options, 'daemon', False): + if ( + getattr(self.options, 'daemon', False) and + not os.environ.get(self._monitor_environ_key) + ): self._warn_daemon_deprecated() try: self.daemonize() @@ -311,15 +314,18 @@ class PServeCommand(object): self.out(str(ex)) return 2 + if ( + not os.environ.get(self._monitor_environ_key) and + self.options.pid_file + ): + self.record_pid(self.options.pid_file) + if ( self.options.monitor_restart and not os.environ.get(self._monitor_environ_key) ): return self.restart_with_monitor() - if self.options.pid_file: - self.record_pid(self.options.pid_file) - if self.options.log_file: stdout_log = LazyWriter(self.options.log_file, 'a') sys.stdout = stdout_log -- cgit v1.2.3 From 389b450da27a91fb413a5eab5ed4a704537ac105 Mon Sep 17 00:00:00 2001 From: Michael Merickel Date: Thu, 12 Nov 2015 22:58:46 -0600 Subject: add changelog entry for #2118 --- CHANGES.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGES.txt b/CHANGES.txt index 8b63cf847..77b8e9298 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -232,6 +232,9 @@ Bug Fixes shell a little more straightfoward. See https://github.com/Pylons/pyramid/pull/1883 +- Fixed usage of ``pserve --monitor-restart --daemon`` which would fail in + horrible ways. See https://github.com/Pylons/pyramid/pull/2118 + Deprecations ------------ -- cgit v1.2.3 From 14d86a4bdd6f371966cb9d08e2886bdf59b6e11f Mon Sep 17 00:00:00 2001 From: Michael Merickel Date: Thu, 12 Nov 2015 23:05:44 -0600 Subject: improve pserve deprecation messages --- pyramid/scripts/pserve.py | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/pyramid/scripts/pserve.py b/pyramid/scripts/pserve.py index 63f34f6c2..3d55fc4f3 100644 --- a/pyramid/scripts/pserve.py +++ b/pyramid/scripts/pserve.py @@ -69,6 +69,7 @@ class PServeCommand(object): If start/stop/restart is given, then --daemon is implied, and it will start (normal operation), stop (--stop-daemon), or do both. + Note: Daemonization features are deprecated. You can also include variable assignments like 'http_port=8080' and then use %(http_port)s in your config files. @@ -100,13 +101,13 @@ class PServeCommand(object): '--daemon', dest="daemon", action="store_true", - help="Run in daemon (background) mode") + help="Run in daemon (background) mode [DEPRECATED]") parser.add_option( '--pid-file', dest='pid_file', metavar='FILENAME', help=("Save PID to file (default to pyramid.pid if running in " - "daemon mode)")) + "daemon mode) [DEPRECATED]")) parser.add_option( '--log-file', dest='log_file', @@ -127,7 +128,7 @@ class PServeCommand(object): '--monitor-restart', dest='monitor_restart', action='store_true', - help="Auto-restart server if it dies") + help="Auto-restart server if it dies [DEPRECATED]") parser.add_option( '-b', '--browser', dest='browser', @@ -137,7 +138,8 @@ class PServeCommand(object): '--status', action='store_true', dest='show_status', - help="Show the status of the (presumably daemonized) server") + help=("Show the status of the (presumably daemonized) server " + "[DEPRECATED]")) parser.add_option( '-v', '--verbose', default=default_verbosity, @@ -169,7 +171,7 @@ class PServeCommand(object): dest='stop_daemon', action='store_true', help=('Stop a daemonized server (given a PID file, or default ' - 'pyramid.pid file)')) + 'pyramid.pid file) [DEPRECATED]')) _scheme_re = re.compile(r'^[a-z][a-z]+:', re.I) @@ -302,6 +304,17 @@ class PServeCommand(object): raise ValueError(msg) writeable_pid_file.close() + # warn before forking + if ( + self.options.monitor_restart and + not os.environ.get(self._monitor_environ_key) + ): + self.out('''\ +--monitor-restart has been deprecated in Pyramid 1.6. It will be removed +in a future release per Pyramid's deprecation policy. Please consider using +a real process manager for your processes like Systemd, Circus, or Supervisor. +''') + if ( getattr(self.options, 'daemon', False) and not os.environ.get(self._monitor_environ_key) -- cgit v1.2.3 From 54251241c8f52dbe88d6ee21df9f2018fbd7c0d9 Mon Sep 17 00:00:00 2001 From: Michael Merickel Date: Thu, 12 Nov 2015 21:41:07 -0600 Subject: abort when using reload with daemon --- pyramid/scripts/pserve.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pyramid/scripts/pserve.py b/pyramid/scripts/pserve.py index 63f34f6c2..42b45640c 100644 --- a/pyramid/scripts/pserve.py +++ b/pyramid/scripts/pserve.py @@ -225,6 +225,10 @@ class PServeCommand(object): cmd = None if self.options.reload: + if self.options.daemon or cmd in ('start', 'stop', 'restart'): + self.out( + 'Error: Cannot use reloading while running as a dameon.') + return 2 if os.environ.get(self._reloader_environ_key): if self.options.verbose > 1: self.out('Running reloading file monitor') -- cgit v1.2.3 From 03465e75ba938a11e9f9c85b7829f7dea9713642 Mon Sep 17 00:00:00 2001 From: Michael Merickel Date: Thu, 12 Nov 2015 23:13:00 -0600 Subject: add changelog for #2119 --- CHANGES.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGES.txt b/CHANGES.txt index 77b8e9298..a17c7e1e6 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -235,6 +235,10 @@ Bug Fixes - Fixed usage of ``pserve --monitor-restart --daemon`` which would fail in horrible ways. See https://github.com/Pylons/pyramid/pull/2118 +- Explicitly prevent ``pserve --reload --daemon`` from being used. It's never + been supported but would work and fail in weird ways. + See https://github.com/Pylons/pyramid/pull/2119 + Deprecations ------------ -- cgit v1.2.3 From baff99d69e80c58a76e0b0e8cf444ee5e573208b Mon Sep 17 00:00:00 2001 From: Michael Merickel Date: Thu, 12 Nov 2015 23:22:00 -0600 Subject: update changelog for #2120 --- CHANGES.txt | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index 77b8e9298..79d610d4a 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -238,9 +238,10 @@ Bug Fixes Deprecations ------------ -- The ``pserve`` command's daemonization features have been deprecated. This - includes the ``[start,stop,restart,status]`` subcommands as well as the - ``--daemon``, ``--stop-server``, ``--pid-file``, and ``--status`` flags. +- The ``pserve`` command's daemonization features have been deprecated as well + as ``--monitor-restart``. This includes the ``[start,stop,restart,status]`` + subcommands as well as the ``--daemon``, ``--stop-daemon``, ``--pid-file``, + and ``--status`` flags. Please use a real process manager in the future instead of relying on the ``pserve`` to daemonize itself. Many options exist including your Operating @@ -248,6 +249,7 @@ Deprecations solutions like Circus and Supervisor. See https://github.com/Pylons/pyramid/pull/1641 + and https://github.com/Pylons/pyramid/pull/2120 - Renamed the ``principal`` argument to ``pyramid.security.remember()`` to ``userid`` in order to clarify its intended purpose. -- cgit v1.2.3