Skip to content

Commit

Permalink
fix(init): convert to metastate; add clean state
Browse files Browse the repository at this point in the history
  • Loading branch information
noelmcloughlin committed Nov 22, 2020
1 parent 8162bdb commit ca5f5aa
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 3 deletions.
25 changes: 23 additions & 2 deletions docs/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,22 @@ Available states
.. contents::
:local:

``redis``
^^^^^^^^^^

``redis``
^^^^^^^^^
*Meta-state (This is a state that includes other states)*.

This state installs the Redis server solution (see https://redis.io)

``redis.clean``
^^^^^^^^^^^^^^^^

*Meta-state (This is a state that includes other states)*.

Stop Redis daemon and remove redis server solution.

``redis.common``
^^^^^^^^^^^^^^^^

Install redis only

Expand All @@ -74,6 +87,14 @@ For options that aren't in the template (timeout, for example in redis-2.8 templ
extra_opts:
timeout: 10
``redis.server.clean``
^^^^^^^^^^^^^^^^^^^^^^

*Meta-state (This is a state that includes other states)*.

Stop Redis daemon and remove redis package/archive.

``redis.sentinel``
^^^^^^^^^^^^^^^^^^

Expand Down
2 changes: 1 addition & 1 deletion kitchen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ suites:
state_top:
base:
'*':
- redis
- redis.common
- redis.server
pillars:
top.sls:
Expand Down
2 changes: 2 additions & 0 deletions redis/clean.sls
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
include:
- redis.server.clean
1 change: 1 addition & 0 deletions redis/init.sls
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
include:
- redis.common
- redis.server
44 changes: 44 additions & 0 deletions redis/server/clean.sls
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@

{%- from "redis/map.jinja" import redis_settings with context %}
{%- set cfg_name = redis_settings.cfg_name -%}
{%- set install_from = redis_settings.install_from -%}
{%- set svc_name = redis_settings.svc_name -%}
{%- set port = redis_settings.port -%}
redis-server-service-clean:
service.dead:
{%- if install_from == 'source' %}
- name: {{ svc_name }}_{{ port }}
{%- else %}
- name: {{ svc_name }}
{%- endif %}
- enable: false
- require_in:
- user: redis-server-clean
- file: redis-server-clean
redis-server-clean:
{%- if install_from == 'source' %}
{%- set user = redis_settings.user -%}
{%- set group = redis_settings.group -%}
user.absent:
- name: {{ user }}
group.absent:
- name: {{ group }}
- require:
- user: redis-server-clean
file.absent:
- names:
- /etc/init/redis-server.conf
- /var/log/redis
- {{ cfg_name }}
- /etc/init.d/redis
- {{ redis_settings.root|default('/usr/local') }}
{%- else %}
pkg.removed:
- name: {{ redis_settings.pkg_name }}
{%- endif %}
5 changes: 5 additions & 0 deletions redis/server/init.sls
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# -*- coding: utf-8 -*-
# vim: ft=sls

include:
- .install
File renamed without changes.

0 comments on commit ca5f5aa

Please sign in to comment.