]> www.infradead.org Git - users/dedekind/aiaiai.git/commitdiff
systemd: add scripts for running the aiaiai processes
authorJacob Keller <jacob.e.keller@intel.com>
Mon, 31 Mar 2014 22:23:59 +0000 (15:23 -0700)
committerArtem Bityutskiy <artem.bityutskiy@linux.intel.com>
Thu, 3 Apr 2014 08:14:10 +0000 (11:14 +0300)
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 <jacob.e.keller@intel.com>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
email/systemd/aiaiai-project-update [new file with mode: 0755]
email/systemd/aiaiai-project-update.service [new file with mode: 0644]
email/systemd/aiaiai-project-update.timer [new file with mode: 0644]
email/systemd/aiaiai.conf [new file with mode: 0644]
email/systemd/aiaiai.service [new file with mode: 0644]
email/systemd/send-mail-on-failure.sh [new file with mode: 0755]
email/systemd/send-mail-on-failure@.service [new file with mode: 0644]

diff --git a/email/systemd/aiaiai-project-update b/email/systemd/aiaiai-project-update
new file mode 100755 (executable)
index 0000000..314e9f3
--- /dev/null
@@ -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] <cfgfile.ini>
+
+The configuration file passed by the argument is parsed for projects. Then,
+git-remote-update is run on each project.
+
+<cfgfile.ini>      - 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 (file)
index 0000000..07356e7
--- /dev/null
@@ -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 (file)
index 0000000..b262fac
--- /dev/null
@@ -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 (file)
index 0000000..456f7d8
--- /dev/null
@@ -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 (file)
index 0000000..939382a
--- /dev/null
@@ -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 (executable)
index 0000000..c382e4e
--- /dev/null
@@ -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 (file)
index 0000000..b0be9f0
--- /dev/null
@@ -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