changeset 1272:3a3f3bccd65b

server: Libervia server is now launched with a Python script, following backend change
author Goffi <goffi@goffi.org>
date Mon, 25 May 2020 15:51:07 +0200
parents b0b9218c5982
children 10748aa888a9
files bin/libervia libervia/server/launcher.py setup.py
diffstat 3 files changed, 36 insertions(+), 113 deletions(-) [+]
line wrap: on
line diff
--- a/bin/libervia	Tue May 19 18:33:18 2020 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,112 +0,0 @@
-#!/bin/sh
-
-DEBUG=""
-DAEMON=""
-PYTHON="python3"
-
-TWISTD="$(which twistd 2>/dev/null)"
-if [ $? -ne 0 ]; then
-	# for Python 3, "twistd" is named "twistd3" on some distros
-	TWISTD="$(which twistd3 2>/dev/null)"
-fi
-if [ $? -ne 0 ]; then
-  	printf "Can't find \"twistd\" script, are you sure that Twisted is installed?\n"	
-	exit 1
-fi
-
-kill_process() {
-    # $1 is the file containing the PID to kill, $2 is the process name
-    if [ -f $1 ]; then
-        PID=`cat $1`
-        if ps -p $PID > /dev/null; then
-            echo "Terminating $2... "
-            kill -INT $PID
-        else
-            echo "No running process of ID $PID... removing PID file"
-            rm -f $1
-        fi
-    else
-        echo "$2 is probably not running (PID file doesn't exist)"
-    fi
-}
-
-#We use python to parse config files
-eval `/usr/bin/env "$PYTHON" << PYTHONEND
-from libervia.server.constants import Const as C
-from sat.tools.config import fixLocalDir
-from configparser import ConfigParser
-from os.path import expanduser, join
-import sys
-
-fixLocalDir()  # XXX: tmp update code, will be removed in the future
-
-config = ConfigParser(defaults=C.DEFAULT_CONFIG)
-try:
-    config.read(C.CONFIG_FILES)
-except:
-    print ("echo \"/!\\ Can't read main config ! Please check the syntax\";")
-    print ("exit 1")
-    sys.exit()
-
-env=[]
-env.append("PID_DIR='%s'" % join(expanduser(config.get('DEFAULT', 'pid_dir')),''))
-env.append("LOG_DIR='%s'" % join(expanduser(config.get('DEFAULT', 'log_dir')),''))
-env.append("APP_NAME='%s'" % C.APP_NAME)
-env.append("APP_NAME_FILE='%s'" % C.APP_NAME_FILE)
-print (";".join(env))
-PYTHONEND
-`
-APP_NAME="$APP_NAME"
-PID_FILE="$PID_DIR$APP_NAME_FILE.pid"
-LOG_FILE="$LOG_DIR$APP_NAME_FILE.log"
-RUNNING_MSG="$APP_NAME is running"
-NOT_RUNNING_MSG="$APP_NAME is *NOT* running"
-
-# if there is one argument which is "stop", then we kill Libervia
-if [ $# -ge 1 ];then
-    if [ $1 = "stop" ];then
-        kill_process $PID_FILE "$APP_NAME"
-        exit 0
-    elif [ $1 = "debug" ];then
-        echo "Launching $APP_NAME in debug mode"
-        DEBUG="--debug"
-    elif [ $1 = "fg" ];then
-        echo "Launching $APP_NAME in foreground mode"
-        DAEMON="n"
-    elif [ $1 = "status" ];then
-		if [ -f $PID_FILE ]; then
-			PID=`cat $PID_FILE`
-			ps -p$PID 2>&1 > /dev/null
-			if [ $? = 0  ];then
-				echo "$RUNNING_MSG (pid: $PID)"
-				exit 0
-			else
-				echo "$NOT_RUNNING_MSG, but a pid file is present (bad exit ?): $PID_FILE"
-				exit 2
-			fi
-		else
-			echo "$NOT_RUNNING_MSG"
-			exit 1
-		fi
-	else
-		echo "bad argument, please use one of (stop, debug, fg, status) or no argument"
-		exit 1
-    fi
-    shift
-fi
-
-
-#Don't change the next lines
-PLUGIN_OPTIONS=""
-AUTO_OPTIONS=""
-ADDITIONAL_OPTIONS="--pidfile $PID_FILE --logfile $LOG_FILE $AUTO_OPTIONS $DEBUG"
-
-
-MAIN_OPTIONS="-${DAEMON}o"
-
-log_dir=`dirname "$LOG_FILE"`
-if [ ! -d $log_dir ] ; then
-    mkdir $log_dir
-fi
-
-exec /usr/bin/env $PYTHON $TWISTD $MAIN_OPTIONS $ADDITIONAL_OPTIONS $APP_NAME_FILE $PLUGIN_OPTIONS $@
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libervia/server/launcher.py	Mon May 25 15:51:07 2020 +0200
@@ -0,0 +1,31 @@
+#!/usr/bin/env python3
+
+# Libervia: a Salut à Toi frontend
+# Copyright (C) 2009-2020 Jérôme Poisson (goffi@goffi.org)
+
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU Affero General Public License for more details.
+
+# You should have received a copy of the GNU Affero General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+"""Script launching Libervia server"""
+
+from sat.core import launcher
+from libervia.server.constants import Const as C
+
+
+class Launcher(launcher.Launcher):
+    APP_NAME=C.APP_NAME
+    APP_NAME_FILE=C.APP_NAME_FILE
+
+
+if __name__ == '__main__':
+    Launcher.run()
--- a/setup.py	Tue May 19 18:33:18 2020 +0200
+++ b/setup.py	Mon May 25 15:51:07 2020 +0200
@@ -84,7 +84,11 @@
         (os.path.join("share", NAME, root), [os.path.join(root, f) for f in files])
         for root, dirs, files in os.walk("themes")
     ],
-    scripts=["bin/libervia"],
+    entry_points={
+        "console_scripts": [
+            "libervia = libervia.server.launcher:Launcher.run",
+            ],
+        },
     zip_safe=False,
     setup_requires=["setuptools_scm"] if is_dev_version else [],
     use_scm_version=libervia_dev_version if is_dev_version else False,