Skip to content

Commit

Permalink
Version 0.3.7: Provide way to disable internal syslog daemon using ei…
Browse files Browse the repository at this point in the history
…ther

a commnad-line switch or configurations setting.
  • Loading branch information
Gary Wisniewski committed May 7, 2016
1 parent 8f313eb commit 6c94400
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 14 deletions.
22 changes: 12 additions & 10 deletions chaperone/cproc/process_manager.py
Expand Up @@ -77,6 +77,7 @@ def __init__(self, config):
self._shutdown_timeout = settings.get('shutdown_timeout', 8) or 0.5

self.detect_exit = settings.get('detect_exit', True)
self.enable_syslog = settings.get('enable_syslog', True)

policy = asyncio.get_event_loop_policy()
w = self._watcher = InitChildWatcher(onNoProcesses = self._queue_no_processes)
Expand Down Expand Up @@ -312,17 +313,18 @@ def _start_system_services(self):

self._notify_enabled = yield from self.notify.connect()

self._syslog = SyslogServer()
self._syslog.configure(self._config, self._minimum_syslog_level)
if self.enable_syslog:
self._syslog = SyslogServer()
self._syslog.configure(self._config, self._minimum_syslog_level)

try:
yield from self._syslog.run()
except PermissionError as ex:
self._syslog = None
warn("syslog service cannot be started: {0}", ex)
else:
self._syslog.capture_python_logging()
info("Switching all chaperone logging to /dev/log")
try:
yield from self._syslog.run()
except PermissionError as ex:
self._syslog = None
warn("syslog service cannot be started: {0}", ex)
else:
self._syslog.capture_python_logging()
info("Switching all chaperone logging to /dev/log")

self._command = CommandServer(self)

Expand Down
2 changes: 1 addition & 1 deletion chaperone/cproc/version.py
@@ -1,7 +1,7 @@
# This file is designed to be used as a package module, but also as a main program runnable
# by Python2 or Python3 which will print the version. Used in setup.py

VERSION = (0,3,6)
VERSION = (0,3,7)
DISPLAY_VERSION = ".".join([str(v) for v in VERSION])

LICENSE = "Apache License, Version 2.0"
Expand Down
1 change: 1 addition & 0 deletions chaperone/cutil/config.py
Expand Up @@ -64,6 +64,7 @@ def IsExecutable(v):
'shutdown_timeout': V.Any(float, int),
'uid': V.Any(str, int),
'logrec_hostname': str,
'enable_syslog': bool,
'status_interval': V.Any(float, int),
},
V.Match('^.+\.logging'): {
Expand Down
11 changes: 8 additions & 3 deletions chaperone/exec/chaperone.py
Expand Up @@ -5,7 +5,8 @@
chaperone [--config=<file_or_dir>]
[--user=<name> | --create-user=<newuser>] [--default-home=<dir>]
[--exitkills | --no-exitkills] [--ignore-failures] [--log-level=<level>] [--no-console-log]
[--debug] [--force] [--disable-services] [--no-defaults] [--version] [--show-dependencies]
[--debug] [--force] [--disable-services] [--no-defaults] [--no-syslog]
[--version] [--show-dependencies]
[--task]
[<command> [<args> ...]]
Expand All @@ -24,6 +25,8 @@
--no-console-log Disable all logging to stdout and stderr (useful when the container produces non-log output)
--no-exitkills When givencommand exits, don't kill the system (default if container running daemon)
--no-defaults Ignores any default options in the CHAPERONE_OPTIONS environment variable
--no-syslog The internal syslog server will not be started (useful when a separate syslog
daemon is started later).
--user=<name> Start first process as user (else root)
--show-dependencies Shows a list of service dependencies then exits
--task Run in task mode (see below).
Expand Down Expand Up @@ -148,9 +151,11 @@ def main_entry():
exit(1)
user = udata['user']

extras = None
extras = dict()
if options['--ignore-failures']:
extras = {'ignore_failures': True}
extras['ignore_failures'] = True
if options['--no-syslog']:
extras['enable_syslog'] = False

try:
config = Configuration.configFromCommandSpec(options['--config'], user=user, extra_settings=extras,
Expand Down
13 changes: 13 additions & 0 deletions doc/source/ref/command-line.rst
Expand Up @@ -38,6 +38,7 @@ command-line switch function
:ref:`--no-console-log <option.no-console-log>` Forces 'stderr' and 'stdout' to *false* for all logging services.
:ref:`--no-defaults <option.no-defaults>` Ignore the :ref:`_CHAP_OPTIONS <env._CHAP_OPTIONS>` environment variable,
if present.
:ref:`--no-syslog <option.no-syslog>` Disable the syslog service at start-up and do not create ``/dev/log``.
:ref:`--user=username <option.user>` Run all processes as ``user`` (uid number or name). The user must exist.
By default, all processes run as ``root``.
:ref:`--create-user=newuser[:uid:gid] <option.create-user>` Create a new user upon start-up with optional ``uid`` and ``gid``. Then
Expand Down Expand Up @@ -255,6 +256,18 @@ Option Reference Information
container internals to ``stdout`` in some format (such as ``gzip``) which may be corrupted if inadvertent console
messages are produced.

.. _option.no-syslog:

.. option:: --no-syslog

This switch tells Chaperone to disable the normal creation of ``/dev/log`` and to perform all of its own logging to the
console. Chaperone defaults to automatically starting its own internal logging service. Disabling syslog can be useful in cases
where a container has some other method of logging, or wants to start a standard
syslog deamon itself.

This switch is equivalent to setting the global setting :ref:`enable_syslog <settings.enable_syslog>` to `false` and will
override any settings in Chaperone's configuration files.

.. _option.no-defaults:

.. option:: --no-defaults
Expand Down
15 changes: 15 additions & 0 deletions doc/source/ref/config-global.rst
Expand Up @@ -49,6 +49,8 @@ Entries below marked with |ENV| support :ref:`environment variable expansion <en
:ref:`shutdown_timeout <settings.shutdown_timeout>` The amount of time Chaperone will wait for services to complete shutdown
before forcing a kill with SIGKILL. Default is 8 seconds.
:ref:`startup_pause <settings.startup_pause>` Specifies the ``startup_pause`` default for services.
:ref:`enable_syslog <settings.enable_syslog>` Specifies whether Chaperone will start its own internal syslog service
at start-up. Defaults to ``true``.
:ref:`detect_exit <settings.detect_exit>` If true (the default), then Chaperone tries to intelligently detect
when all processes have exit and none are schedule, then terminates.
:ref:`uid <settings.uid>` The default uid (name or number) for all services and logging tasks.
Expand Down Expand Up @@ -158,6 +160,19 @@ This delay is useful in at least two common situations:

If a service specifies its own value, it will always take precedence over this default.

.. _settings.enable_syslog:

.. describe:: enable_syslog

This setting allows you to enable or disable Chaperone's internal syslog service. If set to ``false`` then
the ``/dev/log`` file will not be created, and Chaperone will not intercept and redirect logging from running
applications. Note that applications which write to ``stdout`` and ``stderr`` will still be intercepted
and processed by Chaperone's logging directives.

If omitted, this setting defaults to `true`.

Syslog can also be disabled by using the Chaperone command line option :ref:`--no-syslog <option.no-syslog>`.

.. _settings.detect_exit:

.. describe:: detect_exit
Expand Down

0 comments on commit 6c94400

Please sign in to comment.