From 4ab8c9a3807fb4b5271cffa0410a554eac19e2a5 Mon Sep 17 00:00:00 2001 From: Jacob Keller Date: Mon, 31 Mar 2014 15:23:59 -0700 Subject: [PATCH] systemd: add scripts for running the aiaiai processes This patch adds 3 service files for use with aiaiai 1) aiaiai.service which runs the aiaiai email dispatcher 2) aiaiai-project-update.service which runs aiaiai-project-update which will update remotes for all projects in the configuration file 3) send-mail-on-failure for notifying an administrator of service errors The services are primarily useful for tracking aiaiai output as well as keeping remotes that aiaiai needs up to date. Signed-off-by: Jacob Keller Signed-off-by: Artem Bityutskiy --- email/systemd/aiaiai-project-update | 93 +++++++++++++++++++++ email/systemd/aiaiai-project-update.service | 13 +++ email/systemd/aiaiai-project-update.timer | 15 ++++ email/systemd/aiaiai.conf | 17 ++++ email/systemd/aiaiai.service | 14 ++++ email/systemd/send-mail-on-failure.sh | 11 +++ email/systemd/send-mail-on-failure@.service | 9 ++ 7 files changed, 172 insertions(+) create mode 100755 email/systemd/aiaiai-project-update create mode 100644 email/systemd/aiaiai-project-update.service create mode 100644 email/systemd/aiaiai-project-update.timer create mode 100644 email/systemd/aiaiai.conf create mode 100644 email/systemd/aiaiai.service create mode 100755 email/systemd/send-mail-on-failure.sh create mode 100644 email/systemd/send-mail-on-failure@.service diff --git a/email/systemd/aiaiai-project-update b/email/systemd/aiaiai-project-update new file mode 100755 index 0000000..314e9f3 --- /dev/null +++ b/email/systemd/aiaiai-project-update @@ -0,0 +1,93 @@ +#!/bin/sh -efu + +# Copyright 2014 Intel Corporation +# Author: Jacob Keller +# License: GPLv2 + +# Run git-remote-update for each unique repository in the aiaiai cfg file + +srcdir="$(readlink -ev -- ${0%/*})" +PATH="$srcdir/..:$srcdir/../email:$srcdir/../helpers:$srcdir/../helpers/libshell:$PATH" + +. shell-error +. shell-args +. shell-signal +. aiaiai-sh-functions +. aiaiai-email-sh-functions + +PROG="${0##*/}" +export message_time="yes" + +if can_switch_to_dash; then + exec dash -euf -- "$srcdir/$PROG" "$@" + exit $? +fi + +# Find all unique repository locations. This helps prevent updating a +# repository multiple times. +find_unique_repositories() +{ + local cfgfile="$1"; shift + + parse_config_supported_projects "$cfgfile" | \ + while read -r prj; do + ini_config_get_or_die path "$cfgfile" "prj_$prj" "path" + printf "%s\n" "$path" + done | sort -u +} + +show_usage() +{ + cat <<-EOF +Usage: $PROG [options] + +The configuration file passed by the argument is parsed for projects. Then, +git-remote-update is run on each project. + + - the configuration file. + +Options: + -v, --verbose be verbose; + -h, --help show this text and exit. +EOF +} + +fail_usage() +{ + [ -z "$1" ] || print "%s\n" "$1" + show_usage + exit 1 +} + +verbose= +TEMP=`getopt -n $PROG -o v,h --long verbose,help -- "$@"` || + fail_usage "" +eval set -- "$TEMP" + +while true; do + case "$1" in + -v|--verbose) + verbose=-v + ;; + -h|--help) + show_usage + exit 0 + ;; + --) shift; break + ;; + *) fail_usage "Unrecognized option: $1" + ;; + esac + shift +done + +[ "$#" -eq 1 ] || fail_usage "Insufficient or too many arguments" +cfgfile="$(readlink -fv -- "$1")"; shift +parse_config "$cfgfile" + +find_unique_repositories "$cfgfile" | \ +while read -r repo; do + verbose "Updating $repo" + + git --git-dir="$(git_dir "$repo")" remote update +done diff --git a/email/systemd/aiaiai-project-update.service b/email/systemd/aiaiai-project-update.service new file mode 100644 index 0000000..07356e7 --- /dev/null +++ b/email/systemd/aiaiai-project-update.service @@ -0,0 +1,13 @@ +# Copyright 2014 Intel Corporation +# Author: Jacob Keller +# License: GPLv2 +[Unit] +Description=Aiaiai Project Updater +OnFailure=send-mail-on-failure@%n.service + +[Service] +User=aiaiai +ExecStart=/home/aiaiai/git/aiaiai/email/systemd/aiaiai-project-update -v /home/aiaiai/work/aiaiai.cfg + +[Install] +WantedBy=multi-user.target diff --git a/email/systemd/aiaiai-project-update.timer b/email/systemd/aiaiai-project-update.timer new file mode 100644 index 0000000..b262fac --- /dev/null +++ b/email/systemd/aiaiai-project-update.timer @@ -0,0 +1,15 @@ +# Copyright 2014 Intel Corporation +# Author: Jacob Keller +# License: GPLv2 +[Unit] +Description=Update aiaiai project repositories + +[Timer] +# Wait for boot to finish +OnBootSec=5min +# Run every minute, so that we keep our trees updated +OnUnitInactiveSec=1min +Unit=aiaiai-project-update.service + +[Install] +WantedBy=multi-user.target diff --git a/email/systemd/aiaiai.conf b/email/systemd/aiaiai.conf new file mode 100644 index 0000000..456f7d8 --- /dev/null +++ b/email/systemd/aiaiai.conf @@ -0,0 +1,17 @@ +# Copyright 2014 Intel Corporation +# Author: Jacob Keller +# License: GPLv2 + +# Default Configuration for aiaiai systemd service +# NOTE: The settings below must exist here, else the systemd service will not be +# created + +# Extra PATH components +PATH=/usr/local/programs/smatch/bin:/usr/bin:/usr/local/bin:/usr/sbin:/usr/local/sbin + +# Queue directory to watch +AIAIAI_QUEUE_DIR=/home/aiaiai/work/email/queue + +# Validator command +AIAIAI_CONFIG_FILE=/home/aiaiai/work/aiaiai.cfg + diff --git a/email/systemd/aiaiai.service b/email/systemd/aiaiai.service new file mode 100644 index 0000000..939382a --- /dev/null +++ b/email/systemd/aiaiai.service @@ -0,0 +1,14 @@ +# Copyright 2014 Intel Corporation +# Author: Jacob Keller +# License: GPLv2 +[Unit] +Description=Aiaiai Email Dispatcher +OnFailure=send-mail-on-failure@%n.service + +[Service] +User=aiaiai +EnvironmentFile=/home/aiaiai/git/aiaiai/email/systemd/aiaiai.conf +ExecStart=/home/aiaiai/git/aiaiai/email/aiaiai-email-dispatcher -v ${AIAIAI_QUEUE_DIR} ${AIAIAI_CONFIG_FILE} + +[Install] +WantedBy=multi-user.target diff --git a/email/systemd/send-mail-on-failure.sh b/email/systemd/send-mail-on-failure.sh new file mode 100755 index 0000000..c382e4e --- /dev/null +++ b/email/systemd/send-mail-on-failure.sh @@ -0,0 +1,11 @@ +#!/bin/sh +# +# Copyright 2014 Intel Corporation +# Author: Jacob Keller +# License: GPLv2 + +( +echo "$1 has crashed, and you need to restart it!" +echo "Here is the systemctl status output:" +systemctl status -n 100 "$1" +) | mutt -s "$1 crashed!" jacob.e.keller@intel.com diff --git a/email/systemd/send-mail-on-failure@.service b/email/systemd/send-mail-on-failure@.service new file mode 100644 index 0000000..b0be9f0 --- /dev/null +++ b/email/systemd/send-mail-on-failure@.service @@ -0,0 +1,9 @@ +# Copyright 2014 Intel Corporation +# Author: Jacob Keller +# License: GPLv2 +[Unit] +Description=Send mail on failure of %i + +[Service] +User=aiaiai +ExecStart=/home/aiaiai/git/aiaiai/systemd/send-mail-on-failure.sh %i -- 2.49.0