Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Initial commit.

  • Loading branch information...
commit d53e552ce8687214cec5c0cca505ccd571905dc9 0 parents
@przemoc authored
Showing with 179 additions and 0 deletions.
  1. +1 −0  .mailmap
  2. +74 −0 README.md
  3. +13 −0 usr/local/bin/abe-run
  4. +91 −0 usr/local/sbin/abe
1  .mailmap
@@ -0,0 +1 @@
+Przemysław Pawełczyk <przemoc@gmail.com>
74 README.md
@@ -0,0 +1,74 @@
+After Boot Executor
+===================
+
+Simple solution for automated tasks execution in Linux.
+
+
+Rationale
+---------
+
+Automated scripts execution just after your system is ready to be used can be
+very handy, especially if you want provide more or less _stable_ environment
+to your tasks requiring running after boot time. ABE helps you here.
+
+
+Installation
+------------
+
+Copy content of this package (excluding top files, i.e. README.md and any other
+files available at this level) to root directory `/`. Add following line to
+`/etc/inittab`:
+
+ abe:23:once:/sbin/getty -inl /usr/local/sbin/abe 38400 tty8
+
+
+Usage
+-----
+
+Just put your scripts in `/tasks/pending` directory and make them executable.
+Next time you boot up your system, they will be executed in a consecutive
+manner (alphabetically ordered). Depending on a returned code, each script will
+be moved to appropriate subdirectory of `/tasks` - `success` or `failure`.
+During execution you can see the results in eighth console (use Ctrl+Alt+F8 to
+show it).
+
+You can apply additional requirements to your scripts by preceding program
+loader defined in shebang with path to `abe-run` and condition, which can be:
+
+* _required-kernel-version_, tested against `uname -r`,
+* `run-as-first-task`, enforcing reboot if it is not the first executed script.
+
+If _required-kernel-version_ is other than the current running one, ABE looks
+for grub entry which title ends with _required-kernel-version_ text and reboots
+into it. If such entry does not exist, script will be moved to `/tasks/skipped`
+directory.
+
+### Shebang example ###
+
+ #!/usr/local/bin/abe-run 2.6.32 /bin/sh
+
+
+Notes
+-----
+
+Proper handling of kernel version dependency in scripts, i.e. automatically
+rebooting into needed kernel, requires `grub` and strict naming convention
+of grub menu entries - they should end with their kernel release text (the one,
+which is returned by `uname -r` if you boot into them).
+
+**USE AT YOUR OWN RISK! NO WARRANTY!**
+
+
+Bugs
+----
+
+If you find any bug, then please create new issue in [GitHub][1] and describe
+it there.
+
+ [1]: http://github.com/przemoc/abe/issues
+
+
+Author
+------
+
+ Przemysław Pawełczyk <przemoc@gmail.com>
13 usr/local/bin/abe-run
@@ -0,0 +1,13 @@
+#!/bin/sh
+
+# After Boot Executor's special task runner
+# Copyright (C) 2009-10 Przemyslaw Pawelczyk <przemoc@gmail.com>
+
+REQ_KREL=$(echo $1 | sed 's/[ \t]\+.*$//')
+
+if [ "$REQ_KREL" != "run-as-first-task" -a "$REQ_KREL" != $(uname -r) ]; then
+ echo "Your current kernel is different from requested: $REQ_KREL"
+ exit 1
+fi
+
+$(echo $* | sed 's/^[^ \t]*[ \t]*//')
91 usr/local/sbin/abe
@@ -0,0 +1,91 @@
+#!/bin/sh
+
+# After Boot Executor
+# Copyright (C) 2009-10 Przemyslaw Pawelczyk <przemoc@gmail.com>
+
+TASKS_DIR=/tasks
+LOG=/var/log/abe
+INITIAL_SLEEP=10
+PREREBOOT_SLEEP=10
+SLEEP_BETWEEN_TASKS=1
+
+GRUB_MENU=/boot/grub/menu.lst
+KREL=$(uname -r)
+#LOG_FORMAT="+%b %e %T $HOSTNAME $0[$$]"
+LOG_FORMAT="+%b %e %T $KREL"
+
+set -e
+
+function log() {
+ date "$LOG_FORMAT: $*" | tee -a $LOG
+}
+
+function sigint_handler() {
+ log "Interrupted"
+ exit 0
+}
+
+function sigterm_handler() {
+ log "Terminated"
+ exit 0
+}
+
+trap sigint_handler SIGINT
+trap sigterm_handler SIGTERM
+
+log "Activating in $INITIAL_SLEEP seconds"
+
+sleep $INITIAL_SLEEP
+
+mkdir -p "$TASKS_DIR"/{success,failure,skipped,pending}
+
+cd "$TASKS_DIR"
+
+I=1
+for TASK in $(ls -1 pending/); do
+ if [ -d "pending/$TASK" -o ! -x "pending/$TASK" ]; then
+ continue
+ fi
+ mv pending/$TASK ./
+ REQ_KREL=$(awk 'NR==1{if($1~/abe-run$/)print $2;else print "any";exit;}' $TASK)
+ if [ -z "$REQ_KREL" ]; then
+ log "Task $TASK has improper format - skipping"
+ mv $TASK skipped/
+ continue
+ fi
+ if [ "$REQ_KREL" == "run-as-first-task" ]; then
+ if [ "$I" -ne "1" ]; then
+ log "Task $TASK needs to be executed as a first one - rebooting in $PREREBOOT_SLEEP seconds"
+ mv $TASK pending/
+ sleep $PREREBOOT_SLEEP
+ reboot
+ exit 0
+ fi
+ elif [ "$REQ_KREL" != "$KREL" -a "$REQ_KREL" != "any" ]; then
+ REQ_KREL_REGEX="$(echo $REQ_KREL | sed 's/\./\\./g;s/+/\\+/g')"
+ ENTRY=$(grep '^title' "$GRUB_MENU" | awk "/$REQ_KREL_REGEX\$/{print NR-1;exit}")
+ if [ -z "$ENTRY" ]; then
+ log "Task $TASK needs unavailable kernel $REQ_KREL - skipping"
+ mv $TASK skipped/
+ continue
+ fi
+ log "Task $TASK needs kernel $REQ_KREL - rebooting in $PREREBOOT_SLEEP seconds"
+ mv $TASK pending/
+ sleep $PREREBOOT_SLEEP
+ yes | grub-reboot $ENTRY
+ exit 0
+ fi
+ log "Task $TASK is executed"
+ if ./$TASK; then
+ RESULT=success
+ else
+ RESULT=failure
+ fi
+ log "Task $TASK ended with $RESULT"
+ mv $TASK $RESULT/
+ I=$((I+1))
+
+ sleep $SLEEP_BETWEEN_TASKS
+done
+
+log "Deactivating"
Please sign in to comment.
Something went wrong with that request. Please try again.