From 8b870ba16ebc92cc8d88db10b8feb1a653411d9b Mon Sep 17 00:00:00 2001 From: Tzafrir Cohen Date: Mon, 6 Apr 2015 17:22:44 +0300 Subject: Initial commit: copy over local-server --- README | 2 + tests/local-server/call_mysql | 5 ++ tests/local-server/httpd/etc/httpd.conf | 17 +++++++ tests/local-server/httpd/logs/.placeholder | 0 tests/local-server/httpd/mime.types | 1 + tests/local-server/mysqld/.placeholder | 0 tests/local-server/mysqld/data/.placeholder | 0 tests/local-server/mysqld/my.cnf | 5 ++ tests/local-server/mysqld/share | 1 + tests/local-server/run_all | 40 +++++++++++++++ tests/local-server/run_httpd | 44 +++++++++++++++++ tests/local-server/run_mysqld | 76 +++++++++++++++++++++++++++++ 12 files changed, 191 insertions(+) create mode 100644 README create mode 100755 tests/local-server/call_mysql create mode 100644 tests/local-server/httpd/etc/httpd.conf create mode 100644 tests/local-server/httpd/logs/.placeholder create mode 120000 tests/local-server/httpd/mime.types create mode 100644 tests/local-server/mysqld/.placeholder create mode 100644 tests/local-server/mysqld/data/.placeholder create mode 100644 tests/local-server/mysqld/my.cnf create mode 120000 tests/local-server/mysqld/share create mode 100755 tests/local-server/run_all create mode 100755 tests/local-server/run_httpd create mode 100755 tests/local-server/run_mysqld diff --git a/README b/README new file mode 100644 index 0000000..50959e6 --- /dev/null +++ b/README @@ -0,0 +1,2 @@ +Files under tests/local-server are intended to run a local instance +of Apache and MySQL using the local directory as a data directory diff --git a/tests/local-server/call_mysql b/tests/local-server/call_mysql new file mode 100755 index 0000000..e48c6a1 --- /dev/null +++ b/tests/local-server/call_mysql @@ -0,0 +1,5 @@ +#!/bin/sh + +# A wrapper arund the mysql command-line client +dir=`dirname $0` +exec mysql --defaults-file=$dir/mysqld/my.cnf "$@" diff --git a/tests/local-server/httpd/etc/httpd.conf b/tests/local-server/httpd/etc/httpd.conf new file mode 100644 index 0000000..d9d7117 --- /dev/null +++ b/tests/local-server/httpd/etc/httpd.conf @@ -0,0 +1,17 @@ +#LoadModule authn_core_module /usr/lib/apache2/modules/mod_authn_core.so +LoadModule authz_core_module /usr/lib/apache2/modules/mod_authz_core.so +LoadModule access_compat_module /usr/lib/apache2/modules/mod_access_compat.so +LoadModule dir_module /usr/lib/apache2/modules/mod_dir.so +LoadModule mime_module /usr/lib/apache2/modules/mod_mime.so +LoadModule mpm_prefork_module /usr/lib/apache2/modules/mod_mpm_prefork.so +LoadModule rewrite_module /usr/lib/apache2/modules/mod_rewrite.so +LoadModule php5_module /usr/lib/apache2/modules/libphp5.so +RewriteEngine on +Options all + + DirectoryIndex index.php + AllowOverride all + + + SetHandler application/x-httpd-php + diff --git a/tests/local-server/httpd/logs/.placeholder b/tests/local-server/httpd/logs/.placeholder new file mode 100644 index 0000000..e69de29 diff --git a/tests/local-server/httpd/mime.types b/tests/local-server/httpd/mime.types new file mode 120000 index 0000000..836d968 --- /dev/null +++ b/tests/local-server/httpd/mime.types @@ -0,0 +1 @@ +/etc/mime.types \ No newline at end of file diff --git a/tests/local-server/mysqld/.placeholder b/tests/local-server/mysqld/.placeholder new file mode 100644 index 0000000..e69de29 diff --git a/tests/local-server/mysqld/data/.placeholder b/tests/local-server/mysqld/data/.placeholder new file mode 100644 index 0000000..e69de29 diff --git a/tests/local-server/mysqld/my.cnf b/tests/local-server/mysqld/my.cnf new file mode 100644 index 0000000..7aee042 --- /dev/null +++ b/tests/local-server/mysqld/my.cnf @@ -0,0 +1,5 @@ +[client] +socket = tests/local-server/mysqld/socket + +[mysqld] +datadir = data diff --git a/tests/local-server/mysqld/share b/tests/local-server/mysqld/share new file mode 120000 index 0000000..a501361 --- /dev/null +++ b/tests/local-server/mysqld/share @@ -0,0 +1 @@ +/usr/share \ No newline at end of file diff --git a/tests/local-server/run_all b/tests/local-server/run_all new file mode 100755 index 0000000..0cfde44 --- /dev/null +++ b/tests/local-server/run_all @@ -0,0 +1,40 @@ +#!/bin/sh + +dir=`dirname $0` +run_mysqld="$dir/run_mysqld" +run_httpd="$dir/run_httpd" +mysql="$dir/call_mysql" +dbname="asterisk" # FIXME: could it be changed? +mysql_rootpw="123456" # FIXME: copied from run_mysqld script +mysql_user="grant-all" +mysql_user_pass="Archibald-Alexander-Leach" +db_dump="db.sql" + +usage() { + me=`basename $0` + echo "$me: runs a local instance of the web app (Apache + MySQL)" + echo "Usage: $me - the usual" + echo "Usage: $me - install / remove the databases" +} + +do_init() { + $run_mysqld init + $run_mysqld start + sleep 1 + ( + echo "CREATE USER '$mysql_user'@'localhost' identified by '$mysql_user_pass'" + echo "CREATE DATABASE $dbname" + echo "GRANT ALL on $dbname.* to '$mysql_user'@'localhost'" + cat $db_dump + ) | $mysql -uroot -p"$mysql_rootpw" + $run_mysqld stop +} + +case "$1" in +start | stop | reload | restart) $run_httpd $1 && $run_mysqld $1;; +status) $run_httpd $1; $run_mysqld $1;; # FIXME: what status do I return? +clean) $run_mysqld $1;; +init) do_init;; +*) usage; exit 1;; +esac + diff --git a/tests/local-server/run_httpd b/tests/local-server/run_httpd new file mode 100755 index 0000000..0df758e --- /dev/null +++ b/tests/local-server/run_httpd @@ -0,0 +1,44 @@ +#!/bin/sh + +HTTPD=/usr/sbin/apache2 +dir=`dirname $0` +ROOT=$dir/httpd +DOC_ROOT=$PWD +PID_FILE="$ROOT/httpd.pid" +PORT=8234 + +usage() { + me=`basename $0` + echo "$me: runs a local instance of apache (on port $PORT)" + echo "Usage: $me - the usual" + echo " $me log cat the log file" +} + +run_httpd() { + $HTTPD -d "$ROOT" -f etc/httpd.conf \ + -C "Listen $PORT" \ + -C "PidFile $PID_FILE" \ + -C "DocumentRoot $DOC_ROOT" \ + "$@" +} + +case "$1" in +start) shift; run_httpd "$@";; +stop) run_httpd -k stop;; +restart) + "$0" stop + sleep 1 + "$0" start + ;; +reload) kill -HUP `cat "$PID_FILE"`;; +status) + if [ -f "$PID_FILE" ]; then + ps `cat "$PID_FILE"` + else + echo "Not running" + fi + ;; +log) cat "$ROOT/logs/error_log";; +*) usage; exit 1;; +esac + diff --git a/tests/local-server/run_mysqld b/tests/local-server/run_mysqld new file mode 100755 index 0000000..ba2c9f5 --- /dev/null +++ b/tests/local-server/run_mysqld @@ -0,0 +1,76 @@ +#!/bin/sh + +set -e + +MYSQLD=/usr/sbin/mysqld +dir=`dirname $0` +ROOT=$dir/mysqld +PID_FILE="$ROOT/mysql.pid" +MY_CNF="$ROOT/my.cnf" +PORT=3316 +ROOTPW=123456 + +usage() { + me=`basename $0` + echo "$me: runs a local instance of apache (on port $PORT)" + echo "Usage: $me - the usual" + echo "Usage: $me - install / remove the databases" +} + +run_mysqld() { + $MYSQLD \ + --defaults-file=$MY_CNF \ + --basedir=$ROOT \ + --pid-file=$PID_FILE \ + --port=$PORT \ + --socket=$ROOT/socket \ + "$@" & +} + +run_mysql_upgrade() { + mysql_upgrade \ + --defaults-file=$MY.CNF \ + "$@" +} + +init_mysql() { + ( + echo "CREATE DATABASE mysql;" + #echo "GRANT ALL on *.* to 'root'@'localhost' identified by '$ROOTPW';" + echo "USE mysql;" + cat /usr/share/mysql/mysql_system_tables.sql + echo "UPDATE user SET password=PASSWORD("$ROOTPW") WHERE user='root';" + echo "FLUSH PRIVILEGES;" + ) | run_mysqld --bootstrap --skip-grant-tables + set -x + run_mysqld + sleep 5 + run_mysql_upgrade + "$0" stop + set +x +} + +case "$1" in +start) shift; run_mysqld "$@";; +init) init_mysql;; +stop) kill `cat "$PID_FILE"`;; +restart) + "$0" stop + #sleep 1 + "$0" start + ;; +reload) kill -HUP `cat "$PID_FILE"`;; +status) + if [ -f "$PID_FILE" ]; then + ps `cat "$PID_FILE"` + else + echo "Not running" + fi + ;; +clean) + # TODO: stop? Check if we're alive? + rm -rf $ROOT/data/* + ;; +*) usage; exit 1;; +esac + -- cgit v1.2.3