← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] ~pappacena/launchpad:autorestart-for-librarian into launchpad:master

 

Thiago F. Pappacena has proposed merging ~pappacena/launchpad:autorestart-for-librarian into launchpad:master.

Commit message:
Automatically restart web server when file changes are detected

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~pappacena/launchpad/+git/launchpad/+merge/377007

I was testing somethings on Zope templates, and it was kind of a pain to manually restart the server every time. So, I've created this small script to detect file changes and automatically restart librarian.

This script is meant to be used in development only (to restart faster, it SIGTERM things and kills processes based on pattern, for example. Things that are not safe to do outside dev envs).
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~pappacena/launchpad:autorestart-for-librarian into launchpad:master.
diff --git a/Makefile b/Makefile
index 62d59e2..f357154 100644
--- a/Makefile
+++ b/Makefile
@@ -323,6 +323,9 @@ start_librarian: compile
 stop_librarian:
 	bin/killservice librarian
 
+watch-librarian:
+	scripts/watch-librarian.sh
+
 $(VERSION_INFO):
 	scripts/update-version-info.sh
 
diff --git a/scripts/watch-librarian.sh b/scripts/watch-librarian.sh
new file mode 100755
index 0000000..28b0f90
--- /dev/null
+++ b/scripts/watch-librarian.sh
@@ -0,0 +1,44 @@
+#!/bin/bash
+LIBRARIAN_COMMAND="bin/run -r librarian -i development"
+
+politely_kill_librarian() {
+  bin/killservice librarian
+}
+
+hard_kill_pid() {
+  PID=$1
+  pkill -9 -P $PID
+  kill -9 $PID
+}
+
+shutdown_watcher() {
+  echo "Exiting watcher..."
+  politely_kill_librarian
+  kill -9 `ps faux | grep "$LIBRARIAN_COMMAND" | cut -d ' ' -f 2`
+  exit $?
+}
+
+# Check dependencies
+which inotifywait >& /dev/null
+if [ $? -ne 0 ]; then
+    echo "Please, run:"
+    echo "    sudo apt-get install inotify-tools"
+    echo "To install inotifywait"
+    exit 1
+fi
+
+trap 'shutdown_watcher' SIGINT
+
+politely_kill_librarian
+
+# Start librarian in background
+while [ 1 ]; do \
+    $LIBRARIAN_COMMAND &
+    LIBRARIAN_PID=$!
+    inotifywait -e modify,create,delete -r lib/ >& /dev/null
+    echo -ne "\n\n- File change detected\n"
+    echo -ne "\t\\_ Restarting librarian...\n\n\n"
+    hard_kill_pid $LIBRARIAN_PID
+done
+
+wait
\ No newline at end of file

Follow ups