diff --git a/pillar/viperserv/bots.sls b/pillar/viperserv/bots.sls index 0a543c5..e8fc402 100644 --- a/pillar/viperserv/bots.sls +++ b/pillar/viperserv/bots.sls @@ -1,57 +1,61 @@ # To regenerate the list of scripts in a folder, try `make list` from rVIPER. viperserv_accounts: viperserv: fullname: ViperServ uid: 833 tc2: fullname: Tau Ceti Central uid: 834 viperserv_bots: Daeghrefn: realname: https://daeghrefn.nasqueron.org scripts: - Daeghrefn/Time.tcl - Daeghrefn/Wolfplex.tcl - Daeghrefn/Server.tcl - Daeghrefn/Last.fm.tcl - Daeghrefn/Wikimedia.tcl - Daeghrefn/Bureautique.tcl - Daeghrefn/Communication.tcl - Daeghrefn/GIS.tcl - Daeghrefn/Tools.tcl - Daeghrefn/Channel.tcl - Daeghrefn/Help.tcl - vendor/oauth.tcl - vendor/proxycheck.tcl modules: - transfer - filesys - seen nickserv: on + ensure_is_live: on Wearg: realname: RabbitMQ broker client scripts: - Wearg/Broker.tcl - Wearg/Notifications.tcl - Wearg/ServersLog.tcl # This one should be last as it initializes # startup components, with broker/Notifications # dependencies - Wearg/Time.tcl nickserv: on + ensure_is_live: on TC2: realname: Tau Ceti Central runas: tc2 scripts: - TC2/Time.tcl - TC2/Server.tcl + ensure_is_live: off # For tests and QA Aeschere: realname: Æschere scripts: {} + ensure_is_live: off diff --git a/roles/viperserv/eggdrop/cron.sls b/roles/viperserv/eggdrop/cron.sls new file mode 100644 index 0000000..cfe7ddf --- /dev/null +++ b/roles/viperserv/eggdrop/cron.sls @@ -0,0 +1,65 @@ +#!py + +# ------------------------------------------------------------- +# Salt — Deploy eggdrop park +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# Project: Nasqueron +# Created: 2018-11-10 +# License: Trivial work, not eligible to copyright +# ------------------------------------------------------------- + +# ------------------------------------------------------------- +# Data helper methods +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + +def get_etc_dir(): + if __grains__['os'] == 'FreeBSD': + return "/usr/local/etc" + + return "/etc" + + +def get_bin_dir(): + if __grains__['os'] == 'FreeBSD': + return "/usr/local/bin" + + return "/bin" + + +def get_eggdrops(): + '''Filter eggdrops to select the ones with ensure_is_live: True''' + return [botname + for botname, bot + in __pillar__['viperserv_bots'].items() + if 'ensure_is_live' in bot and bot['ensure_is_live']] + + +# ------------------------------------------------------------- +# Configuration provider +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + +def run(): + script = get_bin_dir() + '/ensure-eggdrops-are-live' + + return { + get_etc_dir() + '/eggdrops-live.conf': {'file.managed': [ + {'source': 'salt://roles/viperserv/eggdrop/files/eggdrops-live.conf'}, + {'template': 'jinja'}, + {'context': { + 'eggdrops': get_eggdrops() + }}, + ]}, + + script: {'file.managed': [ + {'source': 'salt://roles/viperserv/eggdrop/files/ensure-eggdrops-are-live.sh'}, + {'mode': 755}, + ]}, + + 'eggdrop_crontab': {'cron.present': [ + {'name': script}, + {'minute': '*/5'}, + {'identifier': 'viperserv.eggdrop'}, + ]} + } diff --git a/roles/viperserv/eggdrop/files/eggdrops-live.conf b/roles/viperserv/eggdrop/files/eggdrops-live.conf new file mode 100644 index 0000000..48439e3 --- /dev/null +++ b/roles/viperserv/eggdrop/files/eggdrops-live.conf @@ -0,0 +1,19 @@ +# ------------------------------------------------------------- +# ViperServ — Deploy eggdrop park +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# Project: Nasqueron +# License: Trivial work, not eligible to copyright +# Source file: roles/viperserv/eggdrop/files/eggdrops-live.conf +# ------------------------------------------------------------- +# +# +# This file is managed by our rOPS SaltStack repository. +# +# Changes to this file may cause incorrect behavior +# and will be lost if the state is redeployed. +# + +# Eggdrops to respawn on failure +{% for eggdrop in eggdrops %} +{{ eggdrop }} +{%- endfor %} diff --git a/roles/viperserv/eggdrop/files/ensure-eggdrops-are-live.sh b/roles/viperserv/eggdrop/files/ensure-eggdrops-are-live.sh new file mode 100755 index 0000000..3459d34 --- /dev/null +++ b/roles/viperserv/eggdrop/files/ensure-eggdrops-are-live.sh @@ -0,0 +1,19 @@ +#!/bin/sh + +while IFS=' ' read -r eggdrop; do + # Skip blank lines and comment lines + take_first_character="?" + first_character=${eggdrop%"${eggdrop#${take_first_character}}"} + if [ "$first_character" = "#" ]; then + continue + elif [ "$eggdrop" = "" ]; then + continue + fi + + service eggdrop status "$eggdrop" > /dev/null + status=$? + + if [ $status -ne 0 ]; then + service eggdrop restart "$eggdrop" + fi +done < /usr/local/etc/eggdrops-live.conf diff --git a/roles/viperserv/eggdrop/init.sls b/roles/viperserv/eggdrop/init.sls index 9983d07..ba6abd3 100644 --- a/roles/viperserv/eggdrop/init.sls +++ b/roles/viperserv/eggdrop/init.sls @@ -1,12 +1,13 @@ # ------------------------------------------------------------- # Salt — Deploy eggdrop park # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # Project: Nasqueron # Created: 2017-11-05 # License: Trivial work, not eligible to copyright # ------------------------------------------------------------- include: - .software - .config - .service + - .cron