Turnkey Linux Appliance de Tryton ERP

Llevo un tiempo trabajando con Turnkey Linux, un proyecto de software libre que consta de una serie de imágenes de servidores de distintos proyectos de software libre. Es una buena opción si no conoces un sistema y quieres probarlo sin tener que investigar como instalarlo, o para crear una instalación personalizada y poder levantar una instancia en cuestión de minutos. En el foro de Turnkey he publicado un patch para crear una imagen de Tryton instalable basada en Turnkey Linux, y en el blog de Domatix he publicado un artículo explicando como aplicar ese patch. En este artículo voy a explicar las partes del patch que he creado y como desarrollar nuevos.

El framework que nos permite modificar las appliances disponibles en Turnkey Linux se llama tklpatch, en la web de Turnkey hay documentación sobre la instalación desde repositorios y desde el código, desde repositorios tuve problemas pero desde el código se instala sin problemas.

Instalación y uso

[cc lang=»bash»]
sudo apt-get install squashfs-tools genisoimage tar gzip git
git clone git://github.com/turnkeylinux/tklpatch.git
sudo make install
[/cc]

Una vez instalado para aplicar el parche solo hay que hacer:

[cc lang=»bash»]
tklpatch imagen.iso patch.tar.gz

[/cc]
Lo que hace tklpatch es montar el sistema de archivos de la imagen iso, y le aplica los cambios que hemos programado en el patch.

Patch tryton_on_lapp.tar.gz

El patch consiste en una serie de ficheros empaquetados en un tar.gz, por un lado tenemos un fichero conf, que es un shell script en el que podemos instalar los paquetes necesarios. Por otro lado tenemos una carpeta overlay que lo que hace es crear ficheros en el sistema de archivos, es decir si creamos en la carpeta overlay una carpeta llamada etc y dentro un fichero tryton.conf, al aplicar el parche se quedará el fichero creado en esa ruta. Dentro de la carpeta overlay también podemos crear scripts que se ejecuten en la primera instalación, estos scripts se crean en la carpeta /usr/local/lib/inithooks, en este patch hemos creado un script que hace que el usuario tryton sea el propietario de los ficheros creados en el overlay.

A continuación detallo el contenido del patch:

 

En el fichero conf

1. Crear un usuario del sistema
[cc lang=»bash»]
/usr/sbin/adduser –quiet –system –group tryton
[/cc]
2. Crear usuario del sistema, para esto es muy importante si tienes en tu pc postgres instalado hay que pararlo antes de ejecutar el patch.
[cc lang=»bash»]
/etc/init.d/postgresql-8.4 stop
/etc/init.d/postgresql-8.4 start
su -c – postgres «createuser tryton –no-superuser –createdb –no-createrole»
[/cc]
Para asociar el password al usuario de la base de datos hay que hacerlo ejecutando un sql, pero como usuario postgres, así que creamos un fichero temporal con el sql.
[cc lang=»bash»]
cat > /tmp/changepass.sql <<"EOF" alter user tryton with password '$PASSWVAR'; EOF su -c - postgres "psql template1 -U postgres -f /tmp/changepass.sql" /etc/init.d/postgresql-8.4 stop [/cc] 3. Actualizamos la información de servicios de turnkey, para que muestre la ip y el puerto para conectarnos al servidor de tryton [cc lang="bash"] USAGE=/etc/confconsole/services.txt sed -i -e '6 a Tryton:    $ipaddr:8000' $USAGE sed -i '9 d' $USAGE [/cc] 4. Actualizamos el nombre del equipo [cc lang="bash"] HOSTNAME=tryton echo "$HOSTNAME" > /etc/hostname sed -i "s|127.0.1.1 \(.*\)|127.0.1.1 $HOSTNAME|" /etc/hosts [/cc] 5. Instalamos los paquetes necesarios [cc lang="bash"] APTSOURCES=/etc/apt/sources.list.d/sources.list COMMENT=`grep 'lucid multiverse' $APTSOURCES` UNCOMMENT=$(echo $COMMENT | sed 's|#||') sed -i "s|$COMMENT|$UNCOMMENT|" $APTSOURCES apt-get update apt-get -y install mercurial python2.6  python-ldap libpq-dev python-dev gcc adduser python-dateutil python-genshi python-lxml python-relatorio python-simplejson python-polib python-pkg-resources python-setuptools python-psycopg2 python-yaml python-cairo python-pycha easy_install psycopg2 easy_install polib easy_install proteus [/cc] 6. Para descargar el servidor de tryton hay varias alternativas, yo he decidido descargar de mercurial, así podre mantenerlo actualizado. Se clona el repositorio y se instala. [cc lang="bash"] cd /opt hg clone http://hg.tryton.org/2.4/trytond/ chown -R tryton:tryton /opt/trytond cd /opt/trytond python setup.py install [/cc] 7. Para los módulos oficiales también los descargo de mercurial, en este caso con una iteración descargo e instalo cada módulo. [cc lang="bash"] REPO="http://hg.tryton.org/2.4/modules/" mkdir /opt/tryton_modules module[0]="account" module[1]="account_be" module[2]="account_de_skr03" module[3]="account_fr" module[4]="account_invoice" module[5]="account_invoice_history" module[6]="account_invoice_line_standalone" module[7]="account_product" module[8]="account_statement" module[9]="account_stock_anglo_saxon" module[10]="account_stock_continental" module[11]="analytic_account" module[12]="analytic_invoice" module[13]="analytic_purchase" module[14]="analytic_sale" module[15]="calendar" module[16]="calendar_classification" module[17]="calendar_scheduling" module[18]="calendar_todo" module[19]="carrier" module[20]="carrier_percentage" module[21]="carrier_weight" module[22]="company" module[23]="company_work_time" module[24]="country" module[25]="currency" module[26]="dashboard" module[27]="google_maps" module[28]="ldap_authentication" module[29]="ldap_connection" module[30]="party" module[31]="party_siret" module[32]="party_vcarddav" module[33]="product" module[34]="product_cost_fifo" module[35]="product_cost_history" module[36]="product_measurements" module[37]="product_price_list" module[38]="production" module[39]="project" module[40]="project_plan" module[41]="project_revenue" module[42]="purchase" module[43]="purchase_invoice_line_standalone" module[44]="purchase_shipment_cost" module[45]="sale" module[46]="sale_opportunity" module[47]="sale_price_list" module[48]="sale_shipment_cost" module[49]="stock" module[50]="stock_forecast" module[51]="stock_inventory_location" module[52]="stock_location_sequence" module[53]="stock_lot" module[54]="stock_product_location" module[55]="stock_split" module[56]="stock_supply" module[57]="stock_supply_day" module[58]="stock_supply_forecast" module[59]="stock_supply_production" module[60]="timesheet" declare -p module for  e in ${module[*]} do cd /opt/tryton_modules hg clone $REPO$e"/" chown -R tryton:tryton $e cd $e python setup.py install done cd / [/cc]

Directorio overlay

  1. Configuración de tryton: /etc/trytond.conf
  2. [cc lang=»bash»]
    #This file is part of Tryton. The COPYRIGHT file at the top level of
    #this repository contains the full copyright notices and license terms.
    [options]

    # Activate the json-rpc protocol
    jsonrpc = *:8000
    #ssl_jsonrpc = False

    # This is the hostname used when generating tryton URI
    #hostname_jsonrpc =

    # Configure the path of json-rpc data
    #jsondata_path = /var/www/localhost/tryton

    # Activate the xml-rpc protocol
    #xmlrpc = *:8069
    #ssl_xmlrpc = False

    # Activate the webdav protocol
    #webdav = *:8080
    #ssl_webdav = False

    # This is the hostname used when generating WebDAV URI
    #hostname_webdav =

    # Configure the database type
    # allowed values are postgresql, sqlite, mysql
    #db_type = postgresql

    # Configure the database connection
    ## Note: Only databases owned by db_user will be displayed in the connection dialog
    ## of the Tryton client. db_user must have create permission for new databases
    ## to be able to use automatic database creation with the Tryton client.
    #db_host = 127.0.0.1
    #db_port = 5432
    db_user = tryton
    db_password = tryton
    #db_minconn = 1
    #db_maxconn = 64

    # Configure the postgresql path for the executable
    #pg_path = None

    # Configure the Tryton server password
    admin_passwd = admin

    # Configure the path of the files for the pid and the logs
    #pidfile = False
    #logfile = False

    #privatekey = server.pem
    #certificate = server.pem

    # Configure the SMTP connection
    #smtp_server = localhost
    #smtp_port = 25
    #smtp_ssl = False
    #smtp_tls = False
    #smtp_password = False
    #smtp_user = False

    # Configure the path to store attachments and sqlite database
    #data_path = /var/lib/trytond

    # Allow to run more than one instance of trytond
    #multi_server = False

    # Configure the session timeout (inactivity of the client in sec)
    #session_timeout = 600

    # Enable psyco module
    # Need to have psyco installed http://psyco.sourceforge.net/
    #psyco = False

    # Enable auto-reload of modules if changed
    #auto_reload = True

    # Prevent database listing
    #prevent_dblist = False

    # Enable cron
    # cron = True

    # unoconv connection
    #unoconv = pipe,name=trytond;urp;StarOffice.ComponentContext

    # Number of retries on database operational error
    # retry = 5

    # Default database language code
    # language = en_US

    # Timezone of the server
    # timezone = False
    [/cc]

  3. Valores por defecto : /etc/default/tryton-server
  4. [cc lang=»bash»]
    # Defaults for trytond initscript

    # Specify the user name (Default: tryton).
    DAEMONUSER=»tryton»

    # Specify an alternate config file (Default: /etc/trytond.conf).
    CONFIGFILE=»/etc/trytond.conf»

    # Specify the log file (Default: /var/log/trytond.log).
    LOGFILE=»/var/log/trytond.log»

    # Specify the verbosity of the server log (-v) (Default: not set).
    #VERBOSE=»-v»

    # Specify the locale for the server to run (Default: en_US).
    #LANG=»de_DE.UTF-8″

    # Additional options that are passed to the Daemon.
    DAEMON_OPTS=»$VERBOSE –config=$CONFIGFILE –logfile=$LOGFILE»
    [/cc]

  5. Script de inicio: /etc/init.d/trytond
  6. [cc lang=»bash»]
    #!/bin/sh

    ### BEGIN INIT INFO
    # Provides: tryton-server
    # Required-Start: $syslog
    # Required-Stop: $syslog
    # Should-Start: $network
    # Should-Stop: $network
    # Default-Start: 2 3 4 5
    # Default-Stop: 0 1 6
    # Short-Description: Application Platform
    # Description: Tryton is an Application Platform serving as a base for a complete ERP software.
    ### END INIT INFO

    PATH=»/sbin:/bin:/usr/sbin:/usr/bin»
    DAEMON=»/usr/local/bin/trytond»

    test -x $DAEMON || exit 0

    NAME=»trytond»
    DESC=»Tryton Application Platform»
    DAEMONUSER=»tryton»
    PIDDIR=»/var/run/$NAME»
    PIDFILE=»$PIDDIR/$NAME.pid»
    LOGFILE=»/var/log/$NAME.log»
    DEFAULTS=»/etc/default/tryton-server»
    CONFIGFILE=»/etc/$NAME.conf»
    DAEMON_OPTS=»–config=$CONFIGFILE –logfile=$LOGFILE»

    # Include tryton-server defaults if available
    if [ -r «$DEFAULTS» ]; then
    . «$DEFAULTS»
    fi

    . /lib/lsb/init-functions

    # Make sure trytond is started with configured locale
    if [ -n $LANG ]; then
    export LANG=$LANG
    fi

    set -e

    do_start() {
    if [ ! -d $PIDDIR ]; then
    mkdir $PIDDIR
    chown $DAEMONUSER:$DAEMONUSER $PIDDIR
    fi

    start-stop-daemon –start –quiet –pidfile $PIDFILE \
    –chuid $DAEMONUSER –background –make-pidfile \
    –exec $DAEMON — $DAEMON_OPTS
    }

    do_stop() {
    start-stop-daemon –stop –quiet –pidfile $PIDFILE \
    –oknodo
    }

    case «$1» in
    start)
    log_daemon_msg «Starting $DESC» «$NAME»
    do_start
    log_end_msg $?
    ;;

    stop)
    log_daemon_msg «Stopping $DESC» «$NAME»
    do_stop
    log_end_msg $?
    ;;
    restart|force-reload)
    log_daemon_msg «Restarting $DESC» «$NAME»
    do_stop
    sleep 1
    do_start
    log_end_msg $?
    ;;
    status)
    status_of_proc -p $PIDFILE $DAEMON $NAME && exit 0 || exit $?
    ;;
    *)
    N=/etc/init.d/$NAME
    echo «Usage: $N {start|stop|restart|force-reload|status}» >&2
    exit 1
    ;;
    esac

    exit 0
    [/cc]

  7. Logs: /var/log/trytond.log
  8. En /usr/lib/inithooks/firtsboot.d/37trytonconf tenemos el script que se ejecutará la primera vez arranquemos el sistema.
  • Asocio a los ficheros del directorio overlay el usuario tryton

[cc lang=»bash»]
chmod +x /etc/init.d/trytond
chown tryton.tryton /etc/trytond.conf
chmod 644 /etc/trytond.conf
chown tryton.tryton /etc/default/tryton-server
chmod 644 /etc/default/tryton-server
chown tryton.tryton /var/log/trytond.log
mkdir /var/lib/trytond
chown tryton:tryton /var/lib/trytond
[/cc]

  • Instalo el servicio de trytond al inicio.

[cc lang=»bash»]
update-rc.d trytond defaults
[/cc]

Hasta aquí está detallado como he instalado el servidor de tryton sobre una imagen de turnkey, esto podría aplicarse para instalar tryton desde el código.

Un comentario sobre “Turnkey Linux Appliance de Tryton ERP

Deja una respuesta

Tu dirección de correo electrónico no será publicada.

Este sitio usa Akismet para reducir el spam. Aprende cómo se procesan los datos de tus comentarios.