KartikMistry has uploaded a new change for review. https://gerrit.wikimedia.org/r/165528
Change subject: WIP: Added initial Debian package ...................................................................... WIP: Added initial Debian package Change-Id: I843b5b5b71ccff3a8016f75bd1e0f31ddaf42322 --- A debian/README.source A debian/apertium-apy.init A debian/apertium-apy.install A debian/apertium-apy.logratate A debian/apertium-apy.postinst A debian/apertium-apy.postrm A debian/apertium-apy.service A debian/changelog A debian/compat A debian/control A debian/copyright A debian/rules A debian/source/format A debian/upstart/apertium-apy.conf A debian/watch 15 files changed, 430 insertions(+), 0 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/operations/debs/contenttranslation/apertium-apy refs/changes/28/165528/1 diff --git a/debian/README.source b/debian/README.source new file mode 100644 index 0000000..535fcd7 --- /dev/null +++ b/debian/README.source @@ -0,0 +1,7 @@ +apertium-apy for Debian +----------------------- + +apertium-apy is part of apertium-tools from upstream Apertium repository. + + -- Kartik Mistry <[email protected]> Wed, 08 Oct 2014 21:21:33 +0530 + diff --git a/debian/apertium-apy.init b/debian/apertium-apy.init new file mode 100644 index 0000000..673c8bb --- /dev/null +++ b/debian/apertium-apy.init @@ -0,0 +1,180 @@ +#!/bin/sh +### BEGIN INIT INFO +# Provides: apertium-apy +# Required-Start: $local_fs $network $remote_fs $syslog +# Required-Stop: $local_fs $network $remote_fs $syslog +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Short-Description: Apertium APY service +# Description: Apertium APY is simple API for Apertium written in Python3 +### END INIT INFO + +# Authors: Gabriel Wicke <[email protected]>, +# Kartik Mistry <[email protected]> + +# Do NOT "set -e" + +# PATH should only include /usr/* if it runs after the mountnfs.sh script +PATH=/sbin:/usr/sbin:/bin:/usr/bin +DESC="Apertium APY service" +NAME=apertium-apy +SCRIPT_PATH=/usr/share/apertium-apy/servlet.py +DAEMON="python3 $SCRIPT_PATH -p 80 /usr/share/apertium/modes" +DAEMON_ARGS="" +PIDFILE=/var/run/$NAME.pid +SCRIPTNAME=/etc/init.d/$NAME + +# Exit if the package is not installed +[ -e "$SCRIPT_PATH" ] || exit 0 + +# Read configuration variable file if it is present +[ -r /etc/default/$NAME ] && . /etc/default/$NAME + +# export the port and host env vars, if set +export PORT +export INTERFACE + +# Load the VERBOSE setting and other rcS variables +. /lib/init/vars.sh + +# Define LSB log_* functions. +# Depend on lsb-base (>= 3.2-14) to ensure that this file is present +# and status_of_proc is working. +. /lib/lsb/init-functions + +# +# Function that starts the daemon/service +# +do_start() +{ + # up the number of fds [sockets] from 1024 + ulimit -n 64000 + + # Return + # 0 if daemon has been started + # 1 if daemon was already running + # 2 if daemon could not be started + + # calling /bin/sh is a hack needed to get output redirection on Ubuntu + # 12.04 LTS, see below + start-stop-daemon --start --quiet --pidfile $PIDFILE -bm \ + -c apertium:apertium --test \ + --exec /bin/sh -- \ + -c "$DAEMON $DAEMON_ARGS >> /var/log/apertium/apertium-apy.log 2>&1" \ + || return 1 + start-stop-daemon --start --quiet --pidfile $PIDFILE -bm \ + -c apertium:apertium \ + --exec /bin/sh -- \ + -c "$DAEMON $DAEMON_ARGS >> /var/log/apertium/apertium-apy.log 2>&1" \ + || return 2 + echo "Started apertium-apy on port $PORT" + + # Cleaner version of the above, but does not work with Ubuntu 12.04 + # LTS as the --no-close parameter is not yet supported there + #start-stop-daemon --start --quiet --pidfile $PIDFILE -bm --no-close \ + # -c apertium:apertium \ + # --exec $DAEMON -- $DAEMON_ARGS >> /var/log/apertium/apertium-apy.log 2>&1 \ + # || return 2 + + # Add code here, if necessary, that waits for the process to be ready + # to handle requests from services started subsequently which depend + # on this one. As a last resort, sleep for some time. + sleep 5 +} + +# +# Function that stops the daemon/service +# +do_stop() +{ + # Return + # 0 if daemon has been stopped + # 1 if daemon was already stopped + # 2 if daemon could not be stopped + # other if a failure occurred + start-stop-daemon --stop --quiet --retry=TERM/60/KILL/5 --pidfile $PIDFILE --name $NAME + RETVAL="$?" + [ "$RETVAL" = 2 ] && return 2 + # Wait for children to finish too if this is a daemon that forks + # and if the daemon is only ever run from this initscript. + # If the above conditions are not satisfied then add some other code + # that waits for the process to drop all resources that could be + # needed by services started subsequently. A last resort is to + # sleep for some time. + start-stop-daemon --stop --quiet --oknodo --retry=0/5/KILL/5 --exec $DAEMON + [ "$?" = 2 ] && return 2 + # Many daemons don't delete their pidfiles when they exit. + rm -f $PIDFILE + return "$RETVAL" +} + +# +# Function that sends a SIGHUP to the daemon/service +# +do_reload() { + # + # If the daemon can reload its configuration without + # restarting (for example, when it is sent a SIGHUP), + # then implement that here. + # + start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE --name $NAME + return 0 +} + +case "$1" in + start) + [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME" + do_start + case "$?" in + 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;; + 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;; + esac + ;; + stop) + [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME" + do_stop + case "$?" in + 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;; + 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;; + esac + ;; + status) + status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $? + ;; + #reload|force-reload) + # + # If do_reload() is not implemented then leave this commented out + # and leave 'force-reload' as an alias for 'restart'. + # + #log_daemon_msg "Reloading $DESC" "$NAME" + #do_reload + #log_end_msg $? + #;; + restart|force-reload) + # + # If the "reload" option is implemented then remove the + # 'force-reload' alias + # + log_daemon_msg "Restarting $DESC" "$NAME" + do_stop + case "$?" in + 0|1) + do_start + case "$?" in + 0) log_end_msg 0 ;; + 1) log_end_msg 1 ;; # Old process is still running + *) log_end_msg 1 ;; # Failed to start + esac + ;; + *) + # Failed to stop + log_end_msg 1 + ;; + esac + ;; + *) + #echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2 + echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2 + exit 3 + ;; +esac diff --git a/debian/apertium-apy.install b/debian/apertium-apy.install new file mode 100644 index 0000000..7cacbfd --- /dev/null +++ b/debian/apertium-apy.install @@ -0,0 +1,4 @@ +*.py usr/share/apertium-apy +Makefile usr/share/apertium-apy +serverlist-example usr/share/apertium-apy +tools usr/share/apertium-apy diff --git a/debian/apertium-apy.logratate b/debian/apertium-apy.logratate new file mode 100644 index 0000000..0182a2f --- /dev/null +++ b/debian/apertium-apy.logratate @@ -0,0 +1,9 @@ +/var/log/apertium/apertium-apy.log { + daily + copytruncate + missingok + compress + notifempty + rotate 15 + size 256M +} diff --git a/debian/apertium-apy.postinst b/debian/apertium-apy.postinst new file mode 100644 index 0000000..724089e --- /dev/null +++ b/debian/apertium-apy.postinst @@ -0,0 +1,56 @@ +#!/bin/sh +# postinst script for apertium +# +# see: dh_installdeb(1) + +set -e + +# summary of how this script can be called: +# * <postinst> `configure' <most-recently-configured-version> +# * <old-postinst> `abort-upgrade' <new version> +# * <conflictor's-postinst> `abort-remove' `in-favour' <package> +# <new-version> +# * <postinst> `abort-remove' +# * <deconfigured's-postinst> `abort-deconfigure' `in-favour' +# <failed-install-package> <version> `removing' +# <conflicting-package> <version> +# for details, see http://www.debian.org/doc/debian-policy/ or +# the debian-policy package + + +case "$1" in + configure) + # make sure that the apertium user exists. Simplest portable way to check + # is to chown something, so we'll create the directories that we need here. + + makedir() { + if [ ! -d $1 ]; then + mkdir $1 + fi + chown -R $2 $1 && chmod $3 $1 + } + + cd /var/log + makedir apertium root:root 700 + chgrp apertium apertium 2>/dev/null || addgroup --system apertium + chown apertium apertium 2>/dev/null || adduser --system --home /usr/lib/apertium --no-create-home \ + --disabled-password --ingroup apertium apertium + # Now that we have the user ready, chown & chmod the log dir + makedir apertium apertium:apertium 700 + ;; + + abort-upgrade|abort-remove|abort-deconfigure) + ;; + + *) + echo "postinst called with unknown argument \`$1'" >&2 + exit 1 + ;; +esac + +# dh_installdeb will replace this with shell code automatically +# generated by other debhelper scripts. + +#DEBHELPER# + +exit 0 diff --git a/debian/apertium-apy.postrm b/debian/apertium-apy.postrm new file mode 100644 index 0000000..db11800 --- /dev/null +++ b/debian/apertium-apy.postrm @@ -0,0 +1,60 @@ +#!/bin/sh +# postrm script for apertium +# +# see: dh_installdeb(1) + +set -e + +# summary of how this script can be called: +# * <postrm> `remove' +# * <postrm> `purge' +# * <old-postrm> `upgrade' <new-version> +# * <new-postrm> `failed-upgrade' <old-version> +# * <new-postrm> `abort-install' +# * <new-postrm> `abort-install' <old-version> +# * <new-postrm> `abort-upgrade' <old-version> +# * <disappearer's-postrm> `disappear' <overwriter> +# <overwriter-version> +# for details, see http://www.debian.org/doc/debian-policy/ or +# the debian-policy package + + +case "$1" in + purge) + + # Delete user; recipe from + # https://wiki.debian.org/AccountHandlingInMaintainerScripts + + USERNAME=apertium + if [ -x "$(command -v deluser)" ]; then + deluser --quiet --system $USERNAME > /dev/null || true + else + echo >&2 "not removing $USERNAME system account because deluser command was not found" + fi + + # Delete directory for pid file + if [ -d "/var/run/apertium" ]; then + rm -rf "/var/run/apertium" + fi + + # Delete directory for log files + if [ -d "/var/log/apertium" ]; then + rm -rf "/var/log/apertium" + fi + ;; + + remove|upgrade|failed-upgrade|abort-install|abort-upgrade|disappear) + ;; + + *) + echo "postrm called with unknown argument \`$1'" >&2 + exit 1 + ;; +esac + +# dh_installdeb will replace this with shell code automatically +# generated by other debhelper scripts. + +#DEBHELPER# + +exit 0 diff --git a/debian/apertium-apy.service b/debian/apertium-apy.service new file mode 100644 index 0000000..a28fed4 --- /dev/null +++ b/debian/apertium-apy.service @@ -0,0 +1,19 @@ +[Unit] +Description=Translation server and API for Apertium +Documentation=http://wiki.apertium.org/wiki/Apertium-apy +After=network.target + +[Service] +# Change this to your username and edit to how you start apy: +User=apertium +WorkingDirectory=/usr/share/apertium-apy +ExecStart=/usr/bin/python3 servlet.py /usr/share/apertium/modes + +# By default, if it restarts >10 times within 5 secs, it marks it as failed and gives up: +Restart=always + +# No reason to have access to shared tmp files: +PrivateTmp=yes + +[Install] +WantedBy=multi-user.target diff --git a/debian/changelog b/debian/changelog new file mode 100644 index 0000000..4951c03 --- /dev/null +++ b/debian/changelog @@ -0,0 +1,5 @@ +apertium-apy (0.1+svn~57510-1) trusty; urgency=low + + * Initial release. + + -- Kartik Mistry <[email protected]> Wed, 08 Oct 2014 21:21:33 +0530 diff --git a/debian/compat b/debian/compat new file mode 100644 index 0000000..ec63514 --- /dev/null +++ b/debian/compat @@ -0,0 +1 @@ +9 diff --git a/debian/control b/debian/control new file mode 100644 index 0000000..bf81e91 --- /dev/null +++ b/debian/control @@ -0,0 +1,32 @@ +Source: apertium-apy +Section: science +Priority: optional +Maintainer: Kartik Mistry <[email protected]> +Build-Depends: debhelper (>= 9), python3-dev +Standards-Version: 3.9.6 +Homepage: http://apertium.org +Vcs-Git: https://gerrit.wikimedia.org/r/operations/debs/contenttranslation/apertium-apy + +Package: apertium-apy +Architecture: any +Depends: adduser, + logrotate, + apertium (>= 3.3), + apertium-lex-tools, + build-essential, + libxml2-dev, + libxslt-dev, + lttoolbox, + python3-lxml, + python3-dev, + python3-pip, + python3-tornado, + zlib1g-dev, + ${misc:Depends}, + ${python3:Depends}, + ${shlibs:Depends} +Enhances: cxserver +Description: Apertium APY service + This package contains Apertium APY which is simple Apertium + API written in Python 3 meant as a drop-in replacement for + ScaleMT. diff --git a/debian/copyright b/debian/copyright new file mode 100644 index 0000000..75eb403 --- /dev/null +++ b/debian/copyright @@ -0,0 +1,23 @@ +Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ +Upstream-Name: apertium-apy +Source: http://svn.code.sf.net/p/apertium/svn/trunk/apertium-tools + +Files: * +Copyright: 2005-2007, Universitat d'Alacant / Universidad de Alicante + 2007-2008, Prompsit Language Engineering S.L. +License: GPL-2+ + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + . + This package 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 General Public License for more details. + . + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. + . + On Debian systems, the complete text of the GNU General + Public License version 2 can be found in "/usr/share/common-licenses/GPL-2". diff --git a/debian/rules b/debian/rules new file mode 100755 index 0000000..782a11a --- /dev/null +++ b/debian/rules @@ -0,0 +1,16 @@ +#!/usr/bin/make -f +# See debhelper(7) (uncomment to enable) +# output every command that modifies files on the build system. +#DH_VERBOSE = 1 + +# see EXAMPLES in dpkg-buildflags(1) and read /usr/share/dpkg/* +DPKG_EXPORT_BUILDFLAGS = 1 +include /usr/share/dpkg/default.mk + +# main packaging script based on dh7 syntax +%: + dh $@ --with python3 + +override_dh_auto_clean: + rm -f langNames.db + dh_auto_clean diff --git a/debian/source/format b/debian/source/format new file mode 100644 index 0000000..163aaf8 --- /dev/null +++ b/debian/source/format @@ -0,0 +1 @@ +3.0 (quilt) diff --git a/debian/upstart/apertium-apy.conf b/debian/upstart/apertium-apy.conf new file mode 100644 index 0000000..e99772c --- /dev/null +++ b/debian/upstart/apertium-apy.conf @@ -0,0 +1,16 @@ +description "Apertium APY service" + +start on (local-filesystems and net-device-up IFACE!=lo) +stop on runlevel [!2345] + +setuid "apertium" +setgid "apertium" + +script + LANG=en_US.utf-8 python3 /usr/share/apertium-apy/servlet.py -p 80 /usr/share/apertium/modes +end script + +respawn + +# wait 60 seconds for a graceful restart before killing the master +kill timeout 60 diff --git a/debian/watch b/debian/watch new file mode 100644 index 0000000..da98b04 --- /dev/null +++ b/debian/watch @@ -0,0 +1 @@ +# apertium-apy is only available in SVN right now. -- To view, visit https://gerrit.wikimedia.org/r/165528 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I843b5b5b71ccff3a8016f75bd1e0f31ddaf42322 Gerrit-PatchSet: 1 Gerrit-Project: operations/debs/contenttranslation/apertium-apy Gerrit-Branch: master Gerrit-Owner: KartikMistry <[email protected]> _______________________________________________ MediaWiki-commits mailing list [email protected] https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
