From 96292a51831ad9c63b9eb0bbe441dd677cc3d50e Mon Sep 17 00:00:00 2001 From: Victor Seva Date: Thu, 12 Sep 2013 10:52:53 +0200 Subject: [PATCH] Added ngcp-panel-[apache|nginx] packages to deal with webservers. Rename ngcp-panel to ngcp-panel-common. The idea is to be able to choose how to serve the webapplication just installing the proper package. --- debian/control | 37 +++++++ debian/ngcp-panel-apache.install | 1 + debian/ngcp-panel-apache.links | 1 + ...el.postinst => ngcp-panel-apache.postinst} | 9 +- debian/ngcp-panel-apache.preinst | 48 ++++++++ ...anel.install => ngcp-panel-common.install} | 2 +- debian/ngcp-panel-nginx.init | 103 ++++++++++++++++++ debian/ngcp-panel-nginx.install | 2 + debian/ngcp-panel-nginx.links | 1 + debian/ngcp-panel-nginx.postinst | 32 ++++++ debian/ngcp-panel-nginx.preinst | 48 ++++++++ debian/rules | 11 +- etc/nginx/ngcp-panel | 17 +++ 13 files changed, 304 insertions(+), 8 deletions(-) create mode 100644 debian/ngcp-panel-apache.install create mode 100644 debian/ngcp-panel-apache.links rename debian/{ngcp-panel.postinst => ngcp-panel-apache.postinst} (75%) create mode 100644 debian/ngcp-panel-apache.preinst rename debian/{ngcp-panel.install => ngcp-panel-common.install} (55%) create mode 100644 debian/ngcp-panel-nginx.init create mode 100644 debian/ngcp-panel-nginx.install create mode 100644 debian/ngcp-panel-nginx.links create mode 100644 debian/ngcp-panel-nginx.postinst create mode 100644 debian/ngcp-panel-nginx.preinst create mode 100644 etc/nginx/ngcp-panel diff --git a/debian/control b/debian/control index 1455cec6b0..df9a9fd18b 100644 --- a/debian/control +++ b/debian/control @@ -44,8 +44,45 @@ Homepage: http://sipwise.com/ Package: ngcp-panel Architecture: all +Depends: ngcp-panel-common (>= 1.0.15), + ngcp-panel-nginx | ngcp-panel-webserver, + ${misc:Depends} +Description: Catalyst based application + A completely overhauled provisioning interface for the + NGCP system. + . + This is a dependency package to install either ngpcp-panel-nginx + (by default) or ngcp-panel-apache. + +Package: ngcp-panel-apache +Architecture: all Pre-Depends: apache2.2-common, libapache2-mod-perl2 +Depends: ngcp-panel-common (>= ${binary:Version}), + ${misc:Depends} +Conflicts: ngcp-panel-nginx +Provides: ngcp-panel-webserver +Description: Catalyst based application. Using mod-perl + A completely overhauled provisioning interface for the + NGCP system. + +Package: ngcp-panel-nginx +Architecture: all +Pre-Depends: nginx-common +Depends: libfcgi-procmanager-perl, + ngcp-panel-common (>= ${binary:Version}), + ngcp-templates-ce-ngcp-panel (>= 3.0.16) | ngcp-templates-pro-ngcp-panel (>=3.0.16), + ${misc:Depends} +Conflicts: ngcp-panel-apache +Provides: ngcp-panel-webserver +Description: Catalyst based application. Using starman+nginx + A completely overhauled provisioning interface for the + NGCP system. + +Package: ngcp-panel-common +Architecture: all +Replaces: ngcp-panel (<< 1.0.15) +Breaks: ngcp-panel (<< 1.0.15) Depends: libcatalyst-actionrole-acl-perl, libcatalyst-modules-perl, libcatalyst-perl (>= 5.90040), diff --git a/debian/ngcp-panel-apache.install b/debian/ngcp-panel-apache.install new file mode 100644 index 0000000000..6623e9f935 --- /dev/null +++ b/debian/ngcp-panel-apache.install @@ -0,0 +1 @@ +etc/apache2/ngcp-panel etc/apache2/sites-available/ diff --git a/debian/ngcp-panel-apache.links b/debian/ngcp-panel-apache.links new file mode 100644 index 0000000000..9ac2c2e2e8 --- /dev/null +++ b/debian/ngcp-panel-apache.links @@ -0,0 +1 @@ +etc/apache2/sites-available/ngcp-panel etc/apache2/sites-enabled/ngcp-panel diff --git a/debian/ngcp-panel.postinst b/debian/ngcp-panel-apache.postinst similarity index 75% rename from debian/ngcp-panel.postinst rename to debian/ngcp-panel-apache.postinst index 79df2b643e..854b88e7c0 100644 --- a/debian/ngcp-panel.postinst +++ b/debian/ngcp-panel-apache.postinst @@ -22,7 +22,7 @@ a2enmod ssl perl a2enmod dump_io || echo "Missing some optional Apache module(s), ignoring." # disable debian's default Apache site -if [ -e /etc/apache2/sites-enabled/default ]; then +if [ -e /etc/apache2/sites-enabled/default ] || [ -e /etc/apache2/sites-enabled/000-default ]; then a2dissite default fi @@ -35,4 +35,9 @@ if [ -x /etc/init.d/apache2 ]; then fi fi -exit 0 +# dh_installdeb will replace this with shell code automatically +# generated by other debhelper scripts. + +#DEBHELPER# + +exit 0 \ No newline at end of file diff --git a/debian/ngcp-panel-apache.preinst b/debian/ngcp-panel-apache.preinst new file mode 100644 index 0000000000..4210ddeaa2 --- /dev/null +++ b/debian/ngcp-panel-apache.preinst @@ -0,0 +1,48 @@ +#!/bin/sh +# preinst script for #PACKAGE# +# +# see: dh_installdeb(1) + +set -e + +# summary of how this script can be called: +# * `install' +# * `install' +# * `upgrade' +# * `abort-upgrade' +# for details, see http://www.debian.org/doc/debian-policy/ or +# the debian-policy package + + +case "$1" in + install|upgrade) + if [ -e /etc/ningx/sites-enabled/ngcp-panel ]; then + echo "Deactivating ngcp-panel on nginx" + rm /etc/ningx/sites-enabled/ngcp-panel + fi + ;; + + abort-upgrade) + ;; + + *) + echo "preinst called with unknown argument \`$1'" >&2 + exit 1 + ;; +esac + +# reload nginx +if [ -x /etc/init.d/nginx ]; then + if [ -x "`which invoke-rc.d 2>/dev/null`" ]; then + invoke-rc.d nginx reload || true + else + /etc/init.d/nginx reload || true + fi +fi + +# dh_installdeb will replace this with shell code automatically +# generated by other debhelper scripts. + +#DEBHELPER# + +exit 0 diff --git a/debian/ngcp-panel.install b/debian/ngcp-panel-common.install similarity index 55% rename from debian/ngcp-panel.install rename to debian/ngcp-panel-common.install index 84869874cd..1c812b48d6 100644 --- a/debian/ngcp-panel.install +++ b/debian/ngcp-panel-common.install @@ -1,3 +1,3 @@ -etc/apache2/ngcp-panel etc/apache2/sites-available/ ngcp_panel.conf etc/ngcp-panel/ share/* usr/share/ngcp-panel/ +debian/tmp/usr/share/* usr/share/ diff --git a/debian/ngcp-panel-nginx.init b/debian/ngcp-panel-nginx.init new file mode 100644 index 0000000000..61dbf3a23f --- /dev/null +++ b/debian/ngcp-panel-nginx.init @@ -0,0 +1,103 @@ +#!/bin/sh +### BEGIN INIT INFO +# Provides: ngcp-panel +# Required-Start: $syslog $network $local_fs $remote_fs $time mysql +# Required-Stop: $syslog $network $local_fs $remote_fs mysql +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Short-Description: Start the ngcp-panel webapp +# Description: Start the ngcp-panel webapp +### END INIT INFO + +. /lib/lsb/init-functions + +DAEMON=/usr/share/ngcp-panel/ngcp_panel_fastcgi.pl +HOMEDIR=/usr/share/ngcp-panel +PIDFILE=/var/run/ngcp-panel.pid +USER=www-data +GROUP=www-data +NAME="ngcp_panel_fastcgi" +DESC="NGCP-Panel Webapp" +USOCKET=/var/run/ngcp-panel.sock +LOGERR=/var/log/ngcp/ngcp-panel.log +NPROC=1 + +OPTIONS="--listen $USOCKET --daemon --pidfile $PIDFILE --nproc $NPROC" + +check_running() { + [ -s $PIDFILE ] && kill -0 $(cat $PIDFILE) >/dev/null 2>&1 +} + +_start() { + rm -f $PIDFILE 2>/dev/null + start-stop-daemon --start --quiet --pidfile $PIDFILE \ + --exec $DAEMON --chdir $HOMEDIR \ + --user $USER --group $GROUP \ + -- $OPTIONS || log_failure_msg "error" +} + +start() { + log_daemon_msg "Starting $DESC: $NAME" + if check_running; then + log_progress_msg "already running" + log_end_msg 0 + exit 0 + fi + _start + log_end_msg $? + return $? +} + +_stop() { + if [ -e $PIDFILE ]; then + if ! check_running ; then + log_daemon_msg " not running" + return 0 + fi + kill `cat $PIDFILE`; + for i in 1 2 3 4 5 6 7; do + echo -n "." + sleep 1; + if check_running ; then + return 0 + fi + done + if check_running ; then + return 1; + fi + fi +} + +stop() { + log_daemon_msg "Stopping $DESC: $NAME" + _stop + log_end_msg $? + return $? +} + +case "$1" in + start) + start + ;; + stop) + stop + ;; + restart|force-reload) + log_daemon_msg "Restarting web application" $NAME + _stop + _start + log_end_msg $? + return $? + ;; + status) + log_daemon_msg "Status of $DESC: " + status_of_proc -p$PIDFILE $DAEMON $NAME + ;; + *) + N=/etc/init.d/$NAME + echo "Usage: $N {start|stop|restart|force-reload|status}" >&2 + exit 1 + ;; +esac + +exit 0 diff --git a/debian/ngcp-panel-nginx.install b/debian/ngcp-panel-nginx.install new file mode 100644 index 0000000000..1ff3092d55 --- /dev/null +++ b/debian/ngcp-panel-nginx.install @@ -0,0 +1,2 @@ +ngcp_panel.psgi usr/share/ngcp-panel/ +script/ngcp_panel_fastcgi.pl usr/share/ngcp-panel/ diff --git a/debian/ngcp-panel-nginx.links b/debian/ngcp-panel-nginx.links new file mode 100644 index 0000000000..451058267b --- /dev/null +++ b/debian/ngcp-panel-nginx.links @@ -0,0 +1 @@ +etc/nginx/sites-available/ngcp-panel etc/nginx/sites-enabled/ngcp-panel diff --git a/debian/ngcp-panel-nginx.postinst b/debian/ngcp-panel-nginx.postinst new file mode 100644 index 0000000000..3bcc3b78c0 --- /dev/null +++ b/debian/ngcp-panel-nginx.postinst @@ -0,0 +1,32 @@ +#!/bin/sh + +set -e + +# don't do anything when called with other argument than configure +case "$1" in + configure) + ;; + abort-upgrade|abort-remove|abort-deconfigure) + exit 0 + ;; + *) + echo "postinst called with unknown argument \$1'" >&2 + exit 1 + ;; +esac + +# reload nginx +if [ -x /etc/init.d/nginx ]; then + if [ -x "`which invoke-rc.d 2>/dev/null`" ]; then + invoke-rc.d nginx restart || true + else + /etc/init.d/nginx restart || true + fi +fi + +# dh_installdeb will replace this with shell code automatically +# generated by other debhelper scripts. + +#DEBHELPER# + +exit 0 \ No newline at end of file diff --git a/debian/ngcp-panel-nginx.preinst b/debian/ngcp-panel-nginx.preinst new file mode 100644 index 0000000000..7d1e71d493 --- /dev/null +++ b/debian/ngcp-panel-nginx.preinst @@ -0,0 +1,48 @@ +#!/bin/sh +# preinst script for #PACKAGE# +# +# see: dh_installdeb(1) + +set -e + +# summary of how this script can be called: +# * `install' +# * `install' +# * `upgrade' +# * `abort-upgrade' +# for details, see http://www.debian.org/doc/debian-policy/ or +# the debian-policy package + + +case "$1" in + install|upgrade) + if [ -e /etc/apache2/sites-enabled/ngcp-panel ]; then + echo "Deactivating ngcp-panel on apache" + rm /etc/apache2/sites-enabled/ngcp-panel + fi + ;; + + abort-upgrade) + ;; + + *) + echo "preinst called with unknown argument \`$1'" >&2 + exit 1 + ;; +esac + +# restart apache +if [ -x /etc/init.d/apache2 ]; then + if [ -x "`which invoke-rc.d 2>/dev/null`" ]; then + invoke-rc.d apache2 restart|| true + else + /etc/init.d/apache2 restart || true + fi +fi + +# dh_installdeb will replace this with shell code automatically +# generated by other debhelper scripts. + +#DEBHELPER# + +exit 0 diff --git a/debian/rules b/debian/rules index 6dd6c4b4ba..f676d3a570 100755 --- a/debian/rules +++ b/debian/rules @@ -1,11 +1,12 @@ #!/usr/bin/make -f +# Uncomment this to turn on verbose mode. +#export DH_VERBOSE=1 + +# This has to be exported to make some magic below work. +export DH_OPTIONS + %: dh $@ -override_dh_install: - dh_install - # remove all *.pl scripts, they are for development usage only - rm -rf ./debian/ngcp-panel/usr/bin - override_dh_auto_test: echo "TODO / FIXME - skipping dh_auto_test" diff --git a/etc/nginx/ngcp-panel b/etc/nginx/ngcp-panel new file mode 100644 index 0000000000..33b1dc6e96 --- /dev/null +++ b/etc/nginx/ngcp-panel @@ -0,0 +1,17 @@ +server { + listen 1443; + ssl on; + ssl_certificate /etc/apache2/ssl/myserver.crt; + ssl_certificate_key /etc/apache2/ssl/myserver.pem; + + location / { + include fastcgi_params; + # adjust parameters for PSGI compatibility + fastcgi_param SCRIPT_NAME ''; + fastcgi_param PATH_INFO $fastcgi_script_name; + fastcgi_pass 127.0.1.1:1433; + } + location /static { + root /usr/share/ngcp-panel; + } +}