diff --git a/debian/control b/debian/control index d2ee9a9..25d6c02 100644 --- a/debian/control +++ b/debian/control @@ -29,11 +29,11 @@ Description: Configuration templates for the web-based CSC interface Package: ngcp-www-csc Architecture: all +Pre-Depends: nginx-common Depends: gettext, - libapache2-request-perl, - libcatalyst-engine-apache-perl, libcatalyst-modules-perl, libcatalyst-perl, + libfcgi-procmanager-perl, liblocale-maketext-lexicon-perl, librpc-xml-perl, ngcp-ossbss-billing (>= 2.0.2), @@ -44,20 +44,3 @@ Depends: gettext, Description: frontend for endusers to configure their accounts on the Sipwise NGCP The CSC framework is used by endusers to configure their accounts on the Sipwise NGCP. - -Package: ngcp-jitsi-redirect -Architecture: all -Depends: apache2, - gettext, - libapache2-mod-perl2, - libapache2-request-perl, - libdata-validate-ip-perl, - libnet-dns-perl, - liblog-log4perl-perl, - liblog-dispatch-perl, - libapache2-mod-apreq2, - ${misc:Depends}, - ${shlibs:Depends} -Description: redirector for Jitsi auto-provisioning - The Jitsi Redirect module points the Sipwise-branded Jitsi to the real - provisioning server defined by the domain part of the SIP URI. diff --git a/debian/ngcp-www-csc.init b/debian/ngcp-www-csc.init new file mode 100644 index 0000000..2a4a4bd --- /dev/null +++ b/debian/ngcp-www-csc.init @@ -0,0 +1,103 @@ +#!/bin/sh +### BEGIN INIT INFO +# Provides: ngcp-www-csc +# Required-Start: $syslog $network $local_fs $remote_fs $time +# Required-Stop: $syslog $network $local_fs $remote_fs +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Short-Description: Start the ngcp-www-csc webapp +# Description: Start the ngcp-www-csc webapp +### END INIT INFO + +. /lib/lsb/init-functions + +HOMEDIR=/usr/share/ngcp-www-csc +DAEMON=$HOMEDIR/script/csc_fastcgi.pl +PIDFILE=/var/run/ngcp-www-csc.pid +USER=www-data +GROUP=www-data +NAME="csc_fastcgi" +DESC="NGCP-CSC Webapp" +USOCKET=/var/run/ngcp-www-csc.sock +LOGERR=/var/log/ngcp/ngcp-www-csc.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-www-csc.postinst b/debian/ngcp-www-csc.postinst index 213879e..15d085f 100644 --- a/debian/ngcp-www-csc.postinst +++ b/debian/ngcp-www-csc.postinst @@ -15,27 +15,35 @@ case "$1" in ;; esac -# enable required modules -a2enmod ssl perl apreq - -# enable optional modules -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 - a2dissite default +# removing old config files +if dpkg-maintscript-helper supports rm_conffile 2>/dev/null; then + dpkg-maintscript-helper rm_conffile \ + /etc/ngcp-config/templates/etc/apache2/sites-available/ngcp-www-csc.tt2 \ + -- "$@" fi -# enable mod_rewrite for port 80 redirection -a2enmod rewrite +# remove default debian site +if [ -e /etc/nginx/sites-enabled/default ]; then + rm /etc/nginx/sites-enabled/default +fi -# reload perl and/or apache modules -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 +if [ -e /etc/nginx/sites-enabled/ngcp-www-csc ]; then + # 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 +else + # who has to create the link? ngcp-templates-[ce|pro]-www-csc? + echo "ngcp-www-csc is not enabled on nginx" fi +# dh_installdeb will replace this with shell code automatically +# generated by other debhelper scripts. + +#DEBHELPER# + exit 0 diff --git a/debian/ngcp-www-csc.preinst b/debian/ngcp-www-csc.preinst new file mode 100644 index 0000000..3e7f020 --- /dev/null +++ b/debian/ngcp-www-csc.preinst @@ -0,0 +1,61 @@ +#!/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/000-default ]; then + echo "Deactivating default site on apache" + rm /etc/apache2/sites-enabled/000-default + FLAG=1 + fi + if [ -e /etc/apache2/sites-enabled/ngcp-www-csc ]; then + echo "Deactivating ngcp-www-csc on apache" + rm /etc/apache2/sites-enabled/ngcp-www-csc + FLAG=1 + fi + if dpkg-maintscript-helper supports rm_conffile 2>/dev/null; then + dpkg-maintscript-helper rm_conffile \ + /etc/ngcp-config/templates/etc/apache2/sites-available/ngcp-www-csc.tt2 \ + -- "$@" + fi + ;; + + abort-upgrade) + ;; + + *) + echo "preinst called with unknown argument \`$1'" >&2 + exit 1 + ;; +esac + +if [ -n "$FLAG" ]; then + # 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 +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 19459a4..a717e71 100755 --- a/debian/rules +++ b/debian/rules @@ -18,14 +18,14 @@ build-stamp: dh_testdir egrep -q "VERSION = 'UNRELEASED'" lib/csc.pm || \ (echo "Wrong version in lib/csc.pm" && exit 2) - mkdir -p pro/etc/ngcp-www-csc pro/etc/apache2/sites-available - mkdir -p ce/etc/ngcp-www-csc ce/etc/apache2/sites-available + mkdir -p pro/etc/ngcp-www-csc pro/etc/nginx/sites-available + mkdir -p ce/etc/ngcp-www-csc ce/etc/nginx/sites-available tpage --define PRO=true etc/csc.conf > pro/etc/ngcp-www-csc/csc.conf.tt2 tpage etc/csc.conf > ce/etc/ngcp-www-csc/csc.conf.tt2 tpage --define PRO=true etc/csc.conf.services > pro/etc/ngcp-www-csc/csc.conf.services tpage etc/csc.conf.services > ce/etc/ngcp-www-csc/csc.conf.services - tpage --define PRO=true etc/apache.site > pro/etc/apache2/sites-available/ngcp-www-csc.tt2 - tpage etc/apache.site > ce/etc/apache2/sites-available/ngcp-www-csc.tt2 + tpage --define PRO=true etc/nginx.site > pro/etc/nginx/sites-available/ngcp-www-csc.tt2 + tpage etc/nginx.site > ce/etc/nginx/sites-available/ngcp-www-csc.tt2 touch $@ clean: @@ -50,6 +50,7 @@ ngcp-www-csc: sed -i -e "s/VERSION = 'UNRELEASED'/VERSION = '$(VERSION)'/" $(b)/$@/usr/share/ngcp-www-csc/lib/csc.pm dh_installexamples -p$@ -P$(b)/$@ dh_installman -p$@ -P$(b)/$@ + dh_installinit -p$@ -P$(b)/$@ dh_link -p$@ -P$(b)/$@ dh_strip -p$@ -P$(b)/$@ dh_compress -p$@ -P$(b)/$@ @@ -99,32 +100,10 @@ ngcp-templates-pro-www-csc: dh_md5sums -p$@ -P$(b)/$@ dh_builddeb -p$@ -P$(b)/$@ -ngcp-jitsi-redirect: - @echo "--- Building: $@" - dh_installdirs -p$@ -P$(b)/$@ - dh_installdocs -p$@ -P$(b)/$@ - dh_installchangelogs -p$@ -P$(b)/$@ - dh_install -p$@ -P$(b)/$@ - dh_installexamples -p$@ -P$(b)/$@ - dh_installman -p$@ -P$(b)/$@ - dh_link -p$@ -P$(b)/$@ - dh_strip -p$@ -P$(b)/$@ - dh_compress -p$@ -P$(b)/$@ - dh_fixperms -p$@ -P$(b)/$@ - #dh_perl -p$@ -P$(b)/$@ - dh_makeshlibs -p$@ -P$(b)/$@ -V - dh_installdeb -p$@ -P$(b)/$@ - dh_shlibdeps -p$@ -P$(b)/$@ - dh_installdebconf -p$@ -P$(b)/$@ - dh_gencontrol -p$@ -P$(b)/$@ - dh_md5sums -p$@ -P$(b)/$@ - dh_builddeb -p$@ -P$(b)/$@ - binary-all: build install binary-indep: build install ngcp-www-csc \ - ngcp-templates-ce-www-csc ngcp-templates-pro-www-csc \ - ngcp-jitsi-redirect + ngcp-templates-ce-www-csc ngcp-templates-pro-www-csc binary: binary-indep binary-arch .PHONY: build clean binary-indep binary-arch binary install diff --git a/etc/csc.conf.services b/etc/csc.conf.services index 8d5af15..20d45ac 100644 --- a/etc/csc.conf.services +++ b/etc/csc.conf.services @@ -1,2 +1,6 @@ [% TAGS [- -] %] -/etc/init.d/apache2 restart || true +[- IF PRO -] +monit restart ngcp-www-csc +[- ELSE -] +/etc/init.d/ngcp-www-csc restart +[- END -] diff --git a/etc/nginx.site b/etc/nginx.site new file mode 100644 index 0000000..9346cb1 --- /dev/null +++ b/etc/nginx.site @@ -0,0 +1,39 @@ +[% TAGS [- -] -%] + +[% IF www_csc.apache.port != 80 && www_admin.apache.port != 80 && ossbss.apache.port != 80 %] +server { + listen [::]:80; + + server_name [% www_csc.apache.servername %]; + + return 301 https://$server_name$request_uri; +} +[% END %] + +server { + listen [::]:[% www_csc.apache.port %]; + [% IF www_csc.apache.ssl_enable == "yes" %] + ssl on; + ssl_certificate [% www_csc.apache.sslcertfile %]; + ssl_certificate_key [% www_csc.apache.sslcertkeyfile %]; + [% END %] + server_name [% www_csc.apache.servername %]; + + location /favicon.ico { + alias /usr/share/ngcp-www-csc/lib/csc/root/favicon.ico; + } + + location /(css|grafik|js) { + root /usr/share/ngcp-www-csc/lib/csc/root; + } + + location / { + include /etc/nginx/fastcgi_params; + # Catalyst requires setting PATH_INFO (instead of SCRIPT_NAME) to $fastcgi_script_name + fastcgi_param SCRIPT_NAME ''; + fastcgi_param PATH_INFO $fastcgi_script_name; + fastcgi_param HTTPS on; + # TODO: configs for fastcgi process + fastcgi_pass unix:/var/run/ngcp-www-csc.sock; + } +} diff --git a/etc/nginx.site.services b/etc/nginx.site.services new file mode 100644 index 0000000..20d45ac --- /dev/null +++ b/etc/nginx.site.services @@ -0,0 +1,6 @@ +[% TAGS [- -] %] +[- IF PRO -] +monit restart ngcp-www-csc +[- ELSE -] +/etc/init.d/ngcp-www-csc restart +[- END -]