[PATCH RFC aiaiai 11/11] systemd: add scripts for running the aiaiai processes

Jacob Keller jacob.e.keller at intel.com
Thu Mar 27 11:40:09 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>
---
 systemd/aiaiai-project-update         | 93 +++++++++++++++++++++++++++++++++++
 systemd/aiaiai-project-update.service | 10 ++++
 systemd/aiaiai-project-update.timer   | 12 +++++
 systemd/aiaiai.service                | 11 +++++
 systemd/email.conf                    | 13 +++++
 systemd/send-mail-on-failure.sh       |  7 +++
 systemd/send-mail-on-failure at .service |  6 +++
 7 files changed, 152 insertions(+)
 create mode 100755 systemd/aiaiai-project-update
 create mode 100644 systemd/aiaiai-project-update.service
 create mode 100644 systemd/aiaiai-project-update.timer
 create mode 100644 systemd/aiaiai.service
 create mode 100644 systemd/email.conf
 create mode 100755 systemd/send-mail-on-failure.sh
 create mode 100644 systemd/send-mail-on-failure at .service

diff --git a/systemd/aiaiai-project-update b/systemd/aiaiai-project-update
new file mode 100755
index 000000000000..314e9f314b84
--- /dev/null
+++ b/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/systemd/aiaiai-project-update.service b/systemd/aiaiai-project-update.service
new file mode 100644
index 000000000000..95ab801c3444
--- /dev/null
+++ b/systemd/aiaiai-project-update.service
@@ -0,0 +1,10 @@
+[Unit]
+Description=Aiaiai Project Updater
+OnFailure=send-mail-on-failure@%n.service
+
+[Service]
+User=aiaiai
+ExecStart=/home/aiaiai/git/aiaiai/systemd/aiaiai-project-update -v /home/aiaiai/work/aiaiai.cfg
+
+[Install]
+WantedBy=multi-user.target
diff --git a/systemd/aiaiai-project-update.timer b/systemd/aiaiai-project-update.timer
new file mode 100644
index 000000000000..e57a9d4bbe0e
--- /dev/null
+++ b/systemd/aiaiai-project-update.timer
@@ -0,0 +1,12 @@
+[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/systemd/aiaiai.service b/systemd/aiaiai.service
new file mode 100644
index 000000000000..e582fc45286c
--- /dev/null
+++ b/systemd/aiaiai.service
@@ -0,0 +1,11 @@
+[Unit]
+Description=Aiaiai Email Dispatcher
+OnFailure=send-mail-on-failure@%n.service
+
+[Service]
+User=aiaiai
+EnvironmentFile=/home/aiaiai/git/aiaiai/systemd/email.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/systemd/email.conf b/systemd/email.conf
new file mode 100644
index 000000000000..6cf464728fad
--- /dev/null
+++ b/systemd/email.conf
@@ -0,0 +1,13 @@
+# Default Configuration for aiaiai-email 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/systemd/send-mail-on-failure.sh b/systemd/send-mail-on-failure.sh
new file mode 100755
index 000000000000..3d7283ffd7c8
--- /dev/null
+++ b/systemd/send-mail-on-failure.sh
@@ -0,0 +1,7 @@
+#!/bin/sh
+
+(
+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/systemd/send-mail-on-failure at .service b/systemd/send-mail-on-failure at .service
new file mode 100644
index 000000000000..bf2b16799237
--- /dev/null
+++ b/systemd/send-mail-on-failure at .service
@@ -0,0 +1,6 @@
+[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