[PATCH aiaiai 1/5] systemd: add scripts for running the aiaiai processes

Jacob Keller jacob.e.keller at intel.com
Mon Mar 31 15:23:59 PDT 2014


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 at intel.com>
---
 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 at .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 at .service

diff --git a/email/systemd/aiaiai-project-update b/email/systemd/aiaiai-project-update
new file mode 100755
index 000000000000..314e9f314b84
--- /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] <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
index 000000000000..07356e7fd170
--- /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 000000000000..b262facc3a33
--- /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 000000000000..456f7d899c48
--- /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 000000000000..939382af7838
--- /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 000000000000..c382e4ed93f6
--- /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 at intel.com
diff --git a/email/systemd/send-mail-on-failure at .service b/email/systemd/send-mail-on-failure at .service
new file mode 100644
index 000000000000..b0be9f0ab43a
--- /dev/null
+++ b/email/systemd/send-mail-on-failure at .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
-- 
1.8.3.1




More information about the aiaiai mailing list