init script installation added and version updated v4.6.0
authorMatteo Nastasi (mop) <nastasi@alternativeoutput.it>
Thu, 17 Jan 2013 07:25:29 +0000 (08:25 +0100)
committerMatteo Nastasi (mop) <nastasi@alternativeoutput.it>
Thu, 17 Jan 2013 07:59:09 +0000 (08:59 +0100)
INSTALL.sh
bin/brisk-init.sh [new file with mode: 0755]
web/Obj/brisk.phh

index bffa041..65074c8 100755 (executable)
@@ -16,60 +16,20 @@ web_path="/home/nastasi/web/brisk"
 ftok_path="/home/nastasi/brisk-priv/ftok/brisk"
 proxy_path="/home/nastasi/brisk-priv/proxy/brisk"
 usock_path="/home/nastasi/brisk-priv/brisk.sock"
+sys_user="www-data"
 legal_path="/home/nastasi/brisk-priv/brisk"
 prefix_path="/brisk/"
 brisk_conf="brisk_spu.conf.pho"
 web_only="FALSE"
 
-
-if [ "$1" = "chk" ]; then
-    set -e
-    oldifs="$IFS"
-    IFS='
-'
-    for i in $(find -name '*.pho' -o -name '*.phh' -o -name '*.php'); do
-        php5 -l $i
-    done
-    exit 0
-fi
-
-# before all check errors on the sources
-$0 chk || exit 3
-
-if [ "$1" = "pkg" ]; then
-    if [ "$2" != "" ]; then
-        tag="$2"
-    else
-        tag="$(git describe)"
-    fi
-    nam1="brisk_${tag}.tgz"
-    nam2="brisk-img_${tag}.tgz"
-    echo "Build packages ${nam1} and ${nam2}."
-    read -p "Proceed [y/n]: " a
-    if [ "$a" != "y" -a  "$a" != "Y" ]; then
-        exit 1
-    fi
-    git archive --format=tar --prefix=brisk-${tag}/brisk/ $tag | gzip > ../$nam1
-    cd ../brisk-img
-    git archive --format=tar --prefix=brisk-${tag}/brisk-img/ $tag | gzip > ../$nam2
-    cd -
-    exit 0
-fi
-    
-if [ -f "$CONFIG_FILE" ]; then
-   source "$CONFIG_FILE"
-fi
-
-if [ "x$prefix_path" = "x" ]; then
-   prefix_path="$web_path"
-fi
-
+#
+# functions
 function usage () {
     echo
     echo "$1 -h"
     echo "$1 chk                          - run lintian on all ph* files."
     echo "$1 pkg                          - build brisk packages."
-    echo "$1 [-W] [-n 3|5] [-t <(n>=4)>] [-T <auth_tab>] [-A <apache-conf>] [-a <auth_file_name>] [-f <conffile>] [-p <outconf>] [-U <usock_path> [-d <TRUE|FALSE>] [-w <web_dir>] [-k <ftok_dir>] [-l <legal_path>] [-y <proxy_path>] [-P <prefix_path>]"
+    echo "$1 [-W] [-n 3|5] [-t <(n>=4)>] [-T <auth_tab>] [-A <apache-conf>] [-a <auth_file_name>] [-f <conffile>] [-p <outconf>] [-U <usock_path>] [-u <sys_user>] [-d <TRUE|FALSE>] [-w <web_dir>] [-k <ftok_dir>] [-l <legal_path>] [-y <proxy_path>] [-P <prefix_path>]"
     echo "  -h this help"
     echo "  -f use this config file"
     echo "  -p save preferences in the file"
@@ -87,7 +47,7 @@ function usage () {
     echo "  -P prefix path                  - def. \"$prefix_path\""
     echo "  -C config filename              - def. \"$brisk_conf\""
     echo "  -U unix socket path             - def. \"$usock_path\""
-    
+    echo "  -u system user to run brisk dae - def. \"$sys_user\""
     echo
 }
 
@@ -125,6 +85,49 @@ function searchetc() {
 #
 #  MAIN
 #
+if [ "$1" = "chk" ]; then
+    set -e
+    oldifs="$IFS"
+    IFS='
+'
+    for i in $(find -name '*.pho' -o -name '*.phh' -o -name '*.php'); do
+        php5 -l $i
+    done
+    exit 0
+fi
+
+# before all check errors on the sources
+$0 chk || exit 3
+
+if [ "$1" = "pkg" ]; then
+    if [ "$2" != "" ]; then
+        tag="$2"
+    else
+        tag="$(git describe)"
+    fi
+    nam1="brisk_${tag}.tgz"
+    nam2="brisk-img_${tag}.tgz"
+    echo "Build packages ${nam1} and ${nam2}."
+    read -p "Proceed [y/n]: " a
+    if [ "$a" != "y" -a  "$a" != "Y" ]; then
+        exit 1
+    fi
+    git archive --format=tar --prefix=brisk-${tag}/brisk/ $tag | gzip > ../$nam1
+    cd ../brisk-img
+    git archive --format=tar --prefix=brisk-${tag}/brisk-img/ $tag | gzip > ../$nam2
+    cd -
+    exit 0
+fi
+
+if [ -f "$CONFIG_FILE" ]; then
+   source "$CONFIG_FILE"
+fi
+
+if [ "x$prefix_path" = "x" ]; then
+   prefix_path="$web_path"
+fi
+
+action=""
 while [ $# -gt 0 ]; do
     # echo aa $1 xx $2 bb
     conffile=""
@@ -144,6 +147,8 @@ while [ $# -gt 0 ]; do
         -C*) brisk_conf="$(get_param "-C" "$1" "$2")"; sh=$?;;
         -l*) legal_path="$(get_param "-l" "$1" "$2")"; sh=$?;;
         -U*) usock_path="$(get_param "-U" "$1" "$2")"; sh=$?;;
+        -u*) sys_user="$(get_param "-u" "$1" "$2")"; sh=$?;;
+        system) action=system;;
         -W) web_only="TRUE";;
         -h) usage $0; exit 0;;
        *) usage $0; exit 1;;
@@ -173,8 +178,9 @@ echo "    ftok_path:  \"$ftok_path\""
 echo "    legal_path: \"$legal_path\""
 echo "    proxy_path: \"$proxy_path\""
 echo "    prefix_path:\"$prefix_path\""
-echo "    brisk_conf:\"$brisk_conf\""
+echo "    brisk_conf: \"$brisk_conf\""
 echo "    usock_path: \"$usock_path\""
+echo "    sys_user:   \"$sys_user\""
 echo "    web_only:   \"$web_only\""
 
 if [ ! -z "$outconf" ]; then
@@ -195,11 +201,36 @@ if [ ! -z "$outconf" ]; then
     echo "prefix_path=\"$prefix_path\""
     echo "brisk_conf=\"$brisk_conf\""
     echo "usock_path=\"$usock_path\""
+    echo "sys_user=\"$sys_user\""
     echo "web_only=\"$web_only\""
   ) > "$outconf"
 fi
 
 max_players=$((40 + players_n * tables_n))
+
+if [ "$action" = "system" ]; then
+    scrname="$(echo "$prefix_path" | sed 's@^/@@g;s@/$@@g;s@/@_@g;')"
+    echo
+    echo "script name:  [$scrname]"
+    echo "brisk path:   [$web_path]"
+    echo "private path: [$legal_path]"
+    echo "system user:  [$sys_user]"
+    echo
+    read -p "press enter to continue" sure
+    cp bin/brisk-init.sh brisk-init.sh.wrk
+    sed -i "s@^BPATH=.*@BPATH=\"${web_path}\"@g;s@^PPATH=.*@PPATH=\"${legal_path}\"@g;s@^SSUFF=.*@SSUFF=\"${scrname}\"@g;s@^BUSER=.*@BUSER=\"${sys_user}\"@g" brisk-init.sh.wrk
+
+    su -c "cp brisk-init.sh.wrk /etc/init.d/${scrname}"
+
+    rm brisk-init.sh.wrk
+    echo
+    echo "... DONE."
+    echo "DON'T FORGET: after the first installation you MUST configure your run-levels accordingly"
+    echo
+    echo "Example: su -c 'update-rc.d $scrname defaults'"
+    echo
+    exit 0
+fi
 #
 #  Pre-check
 #
diff --git a/bin/brisk-init.sh b/bin/brisk-init.sh
new file mode 100755 (executable)
index 0000000..a6aee76
--- /dev/null
@@ -0,0 +1,61 @@
+#!/bin/sh -e
+### BEGIN INIT INFO
+# Provides:          brisk
+# Required-Start:       $local_fs $remote_fs $network $time
+# Required-Stop:        $local_fs $remote_fs $network $time
+# Default-Start:        2 3 4 5
+# Default-Stop:         0 1 6
+# Short-Description: manage brisk daemon
+### END INIT INFO
+
+BPATH="xx/home/nastasi/web/brisk"
+PPATH="xx/home/nastasi/brisk-priv"
+# screen suffix
+SSUFF="xxbrisk"
+BUSER="xxwww-data"
+# seconds to wait exit of the process
+WAITLOOP_MAX=5
+
+#
+#  MAIN
+#
+NL="
+"
+TB="   "
+# scr_old="$(screen -ls | sed "s/^[ ${TB}]*//g;s/[ ${TB}]\+/ /g" | cut -d ' ' -f 1 | grep "\.${SSUFF}$")"
+# echo "[$scr_old]"
+
+case "$1" in
+    stop)
+        #
+        #  if .pid file exists try to shutdown the process
+        if [ -f "${PPATH}/brisk.pid" ]; then
+            pid_old="$(cat "${PPATH}/brisk.pid")"
+            kill -TERM $pid_old
+            killed=0
+            for i in $(seq 1 $WAITLOOP_MAX); do
+                sleep 1
+                if ! kill -0 $pid_old 2>/dev/null ; then
+                    killed=1
+                    break
+                fi
+            done
+            if [ $killed -eq 0 ]; then
+                kill -KILL $pid_old 2>/dev/null
+            fi
+        fi
+        ;;
+
+    start)
+        su - ${BUSER} -c 'cd '"$BPATH"'/spush ; screen -d -m -S '"${SSUFF}"' bash -c '"'"'while [ 1 ]; do ./brisk-spush.php \| grep "IN LOOP" ; if [ $? -eq 0 ]; then break ; fi ; done'"'"
+        ;;
+    restart)
+        $0 stop
+        sleep 3
+        $0 start
+        ;;
+    *)
+        echo "Usage: $0 {start|stop|restart}" >&2
+        exit 1
+        ;;
+esac
index df9bda9..804c6ee 100644 (file)
@@ -140,10 +140,10 @@ $mlang_brisk = array( 'btn_backstand'=> array( 'it' => 'torna in piedi',
 $G_lng = langtolng($G_lang);
 
 $G_all_points = array( 11,10,4,3,2, 0,0,0,0,0 );
-$G_brisk_version = "4.5.5";
+$G_brisk_version = "4.6.0";
 
 /* MLANG: ALL THE INFO STRINGS IN brisk.phh */
-$root_wellarr = array( 'it' => array ( 'Brisk (Ver. '.$G_brisk_version.'), <b>NOVITA\'</b>: nuova visualizzazione dello stato della connessione dati, ... , migliorata la gestione dei tavoli in caso di piccoli blocchi del server, gestione data di login.',
+$root_wellarr = array( 'it' => array ( 'Brisk (Ver. '.$G_brisk_version.'), <b>NOVITA\'</b>: aggiunti script di avvio automatico, gestione dei segnali e logging dell\' ultima connessione.',
                                        'Se vuoi iscriverti alla <a target="_blank" href="mailto:ml-briscola+subscribe@milug.org">Mailing List</a>, cliccala!' ),
                        'en' => array ( 'Brisk (Ver. '.$G_brisk_version.'), <b>NEWS</b>: usage of reader/writer locking instead of generic exclusive locking.',
                                        'If you want to subscribe our <a target="_blank" href="ml-briscola+subscribe@milug.org">Mailing List</a>, click it!' ) );