Skip to content

Commit

Permalink
feat: require swap to run before datadoge (#464)
Browse files Browse the repository at this point in the history
* feat: require swap to run before datadoge

* fix: check for swap path existance first
  • Loading branch information
JacobCoffee authored Aug 14, 2024
1 parent d871897 commit 8112059
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 14 deletions.
6 changes: 3 additions & 3 deletions pillar/prod/swapfile.sls
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
swapfile:
size: 1024
path: /swapfile
swap_file:
swap_size: 1024
swap_path: /swapfile
22 changes: 11 additions & 11 deletions salt/base/swap.sls
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
{% set swapfile = salt["pillar.get"]("swapfile", {}) %}
{% set size = swapfile.get("size", "1024") %}
{% set path = swapfile.get("path") %}
{% set swap_file = salt["pillar.get"]("swap_file", {}) %}
{% set swap_size = swap_file.get("swap_size", "1024") %}
{% set swap_path = swap_file.get("swap_path") %}

{% if path %}
{{ path }}:
{% if swap_path %}
{{ swap_path }}:
cmd.run:
- name: |
swapon --show=NAME --noheadings | grep -q "^{{ path }}$" && swapoff {{ path }}
rm -f {{ path }}
fallocate -l {{ size }}M {{ path }}
chmod 0600 {{ path }}
mkswap {{ path }}
- unless: bash -c "[[ $(($(stat -c %s {{ path }}) / 1024**2)) = {{ size }} ]]"
swapon --show=NAME --noheadings | grep -q "^{{ swap_path }}$" && swapoff {{ swap_path }}
rm -f {{ swap_path }}
fallocate -l {{ swap_size }}M {{ swap_path }}
chmod 0600 {{ swap_path }}
mkswap {{ swap_path }}
- unless: bash -c "[[ $(($(stat -c %s {{ swap_path }}) / 1024**2)) = {{ swap_size }} ]]"

mount.swap:
- persist: true
Expand Down
1 change: 1 addition & 0 deletions salt/datadog/init.sls
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ datadog-agent:
- installed
- require:
- pkgrepo: datadog_repo
- mount: {% if swap_path %}{{ swap_path }}{% endif %}
service:
- running
- enable: True
Expand Down

0 comments on commit 8112059

Please sign in to comment.