Add env variable to diable service

pull/8/head
Christophe Mehay 8 years ago
parent 6c1274404d
commit ea72fac83c

@ -251,6 +251,7 @@ Some setups can be overridden using environment variables.
- `ENTRYPOINT_DISABLE_RELOAD` disable reload system even if it is enabled in `entrypoint-config.yml`.
- `ENTRYPOINT_USER` overrides `user` in config.
- `ENTRYPOINT_GROUP` overrides `group` in config.
- `ENTRYPOINT_DISABLE_SERVICE` exits container with 0 before doing anything. Useful to disable container using environement.

@ -18,3 +18,4 @@ Some setups can be overridden using environment variables in the container.
in ``entrypoint-config.yml``.
- ``ENTRYPOINT_USER`` overrides ``user`` in config.
- ``ENTRYPOINT_GROUP`` overrides ``group`` in config.
- ``ENTRYPOINT_DISABLE_SERVICE`` exits container with 0 before doing anything. Useful to disable container using environement.

@ -53,6 +53,11 @@ class Entrypoint(object):
"""Is command handled by entrypoint"""
return self.config.command.is_handled
@property
def is_disabled(self):
"""Return if service is disabled using environment"""
return 'ENTRYPOINT_DISABLE_SERVICE' in os.environ
@property
def should_config(self):
"""Check environment to tell if config should apply anyway"""
@ -63,6 +68,15 @@ class Entrypoint(object):
"""Check if command output should be displayed using logging or not"""
return 'ENTRYPOINT_RAW' in os.environ
def exit_if_disabled(self):
"""Exist 0 if service is disabled"""
if not self.is_disabled:
return
self.log.warning("Service is disabled by 'ENTRYPOINT_DISABLE_SERVICE' "
"environement variable... exiting with 0")
exit(0)
def apply_conf(self):
"""Apply config to template files"""
env = Environment(loader=FileSystemLoader('/'))
@ -120,6 +134,7 @@ def main(argv):
argv.pop(0)
entry = Entrypoint(args=argv)
try:
entry.exit_if_disabled()
if not entry.is_handled and not entry.should_config:
entry.log.warning("Running command without config")
entry.launch()

@ -1,5 +1,3 @@
PyYAML==3.11
Pygments==2.0.2
argparse==1.4.0
aspy.yaml==0.2.1
blessings==1.6
@ -16,6 +14,8 @@ jsonschema==2.5.1
nodeenv==0.13.6
ordereddict==1.1
pre-commit==0.7.5
Pygments==2.0.2
PyYAML==3.11
requests==2.7.0
six==1.10.0
texttable==0.8.4

@ -5,7 +5,7 @@ from setuptools import setup
# Thanks Sam and Max
__version__ = '0.4.2'
__version__ = '0.4.3'
if __name__ == '__main__':
setup(

@ -6,6 +6,7 @@ import fnmatch
import os
from multiprocessing import Process
import pytest
from yaml import load
from yaml import Loader
@ -268,6 +269,8 @@ def test_user_env():
assert entry.config.user == 1009
del os.environ['ENTRYPOINT_USER']
def test_group_env():
os.environ['ENTRYPOINT_GROUP'] = '100'
@ -279,3 +282,17 @@ def test_group_env():
entry = Entrypoint(conf='configs/base.yml')
assert entry.config.group == 1010
del os.environ['ENTRYPOINT_GROUP']
def test_disabled_service():
os.environ['ENTRYPOINT_DISABLE_SERVICE'] = 'true'
entry = Entrypoint(conf='configs/base.yml')
assert entry.is_disabled
with pytest.raises(SystemExit):
entry.exit_if_disabled()
del os.environ['ENTRYPOINT_DISABLE_SERVICE']

Loading…
Cancel
Save