tryton-server for openSUSE
==========================

How to get it running (Without reading the instructions)
========================================================

You have already installed the package trytond and found this documentation. Good.

1) Log in as root and start the database
> su
> systemctl start postgresql

2) Change postgres parameters. You need to log in as user postgres, in order to avoid authorisation issues. Assuming we have nano as editor:
<you are logged in as user 'root'>

> su postgres
> nano /var/lib/pgsql/data/pg_hba.conf

Change the line
    local   all             all                                     md5
to
    local   all             all                                     trust
Save your input.

Save your input. 

3) Create a role for 'tryton' in the database (sill as user postgres)
> psql -c "CREATE USER tryton WITH CREATEDB;"

4) exit as user postgres and restart postgres
> exit
> systemctl restart postgresql

5) start trytond:
> systemctl start trytond

6) Install the tryton client:
> zypper in tryton

7) Open the tryton client:
>tryton
go to 'manage profiles' -> add -> name it 'localhost' -> Host: localhost
-> you should now see a selection of available databases

Note: From Tryton Release 4.2 onwards it is not possible anymore to create databases from the Frontend. You need to do this manually (see below)

DONE.

Setup (a bit more in detail)
============================

Preparing the database
----------------------

Tryton uses a Relational Database Management System (RDBMS) to store data. The
preferred RDBMS for Tryton is PostgreSQL.

The following steps guide you through the setup:

  * Make sure PostgreSQL is running:

    > systemctl status postgresql

    Note: If PostgreSQL runs on another machine than the Tryton server, make sure
    you have setup database password authentication. Please refer to the
    PostgreSQL manual how to do this. 

    To allow Tryton Server to connect to postgres, md5 authentication should be used.
    In the configuration file /var/lib/pgsql/data/pg_hba.conf change the lines

    # IPv4 local connections:
    host    all             all             127.0.0.1/32            ident
    # IPv6 local connections:
    host    all             all             ::1/128                 ident

    to:
    # IPv4 local connections:
    host    all             all             127.0.0.1/32            md5
    # IPv6 local connections:
    host    all             all             ::1/128                 md5
    
    Restart the server for the changes to take effect.
    
  * Creating the database user:
    
    The Tryton Server runs as user 'tryton', so we need a role in postgres for this.
    
    For manual database creation (standard as from Tryton 4.2 onwards) it is sufficient to create the user as follows:
    
    > su postgres
    > psql -c "CREATE USER tryton WITH CREATEDB;" 
    
    Note: If you want to run the database as another user than 'tryton', you
    need to replace 'tryton' above with the user you want to use instead.

Preparing the Tryton server
---------------------------

  * Setting up the Tryton server (trytond):

    The openSUSE package comes with a working configuration example, see 
    /usr/share/doc/packages/trytond/trytond.conf.example
    It contains all settings for a locally running database and manual database
    configuration.
    
    Adjust /etc/tryton/trytond.conf to reflect any different the setup of your system.
    
  * If the Tryton server shall listen on some external interface (i.e. shall be
    available for clients connecting from other machines), change the jsonrpc
    protocol to listen accordingly.

  * If the Tryton server is listening on external interfaces, it is highly
    recommended to enable SSL for the connection.

    Note: See https://code.google.com/p/tryton/wiki/InstallationonopenSUSE#Setting_up_SSL_communication_with_the_Tryton_server
    for a description to set up certificates

  * Restarting trytond:

    > systemctl restart trytond

    Note: The fingerprint of connected servers is stored in the clients
    known_hosts file. When a server is changed for its SSL usage, the client
    will refuse to reconnect to this server. Removing the according line
    from ~/.config/tryton/<version>/known_hosts will allow to connect to
    the server again.


Now you are ready to connect with a client, e.g. tryton-client.

Creating the database for Tryton
--------------------------------

For manual creation of the database, the following steps are to be performed:

  * Creating the database:

    > su - postgres -c "createdb mydb --encoding='UTF-8' --owner=tryton"

    Note: The owner of the database should be the same user, as under which the 
    tryton server runs (default:tryton) Enter a name for the database 
    (here as default: mydb).

  * Initializing the database:
  
    Log in as user tryton: 

    > sudo su tryton -s /bin/bash
    > /usr/bin/trytond-admin -c /etc/tryton/trytond.conf --all -d mydb

    Note: Use the database name you chose in the previous step (here as default: 
    mydb). You will be asked for the admin password for this database. 
    For the first time, log in to the newly initialized database with user 'admin' 
    and password as set during initialization.

As result you will have a bare Tryton database with the base modules installed.

See: http://doc.tryton.org/4.2/trytond/doc/topics/configuration.html


Installation of the Webfrontend for tryton (sao) from package
-------------------------------------------------------------

For most openSUSE Flavours tryton-sao is packed. You can install it with
     > zypper install tryton-sao

You need to edit /etc/tryton/trytond.conf. Installation of tryton-sao follows the 
standards for nodejs-installations, so the path is within the node-modules:

In the section [web], set the path:
    root = /usr/lib/node-modules/tryton-sao

Now restart trytond.

Installation of the Webfrontend for tryton (sao) from source
------------------------------------------------------------

In case you want to install sao from source:
sao bases on nodejs, and it comes as separate package. Download and extract 
tryton-sao into a directory, say /srv/tryton-sao

Make sure you have nodejs and git installed:
    > zypper install nodejs git phantomjs

Now change into to installation directory and install sao:
    > cd /srv/tryton-sao/package
    > npm install

Now you need to run grunt. make sure it is run from the locally installed version:
    > cd /srv/tryton-sao/package
    > node_modules/grunt-cli/bin/grunt

Last but not least, edit /etc/tryton/trytond.conf
In the section [web], set the path:
    root = /srv/tryton-sao/package

Now restart trytond.
    

Upgrade
-------

  * Once you have upgraded to a new major version (second number of the
    version string) you have to update your database(s).
    After the categorically recommended backup do:

    > /usr/bin/trytond-admin -c /etc/tryton/trytond.conf --all -d mydb

    Remember to replace tryton with the name of your database.


Notes
-----

Now, you're finished with the system setup. Please be aware of the following things:

  * trytond runs by default under the user 'tryton', who is setup as no-login. 
    If you need to login as user tryton, use su - tryton -s /bin/bash

  * trytond has one default account for server administration:
    - User: admin; password: the one you have configured in trytond.conf
    as super_pwd. This user is the one used for database management tasks
    from the client.

    Note: Each Tryton database will have its own admin with login password
    stored in the database itself (not to be confound with the admin of the
    Tryton Server).

  * trytond must have read access to its configuration file, otherwise it will
    start with internal defaults. The postinst script will (re)set ownership to
    the system user running trytond and correct the permissions on the standard
    configuration file (/etc/tryton/trytond.conf).

  * trytond listens by default on port 8000 (jsonrpc). If you need to change
    this, edit /etc/tryton/trytond.conf in the section [jsonrpc].

  * trytond in its upstream configuration listens by default to the localhost
    interface. If you want to change this default to listen on all interfaces,
    edit /etc/tryton/trytond.conf in the section [jsonrpc].

  * modules can be installed via YaST or zypper, e.g. zypper in trytond_account
  
  * Installation of modules into the database can be done from the
    Administration Panel of the client. Under Modules you can select from the
    modules packages (trytond_*) you have installed on your system. 
        
  * Only the same major version of Tryton client and Tryton server can connect.

 -- Axel Braun <axel.braun@gmx.de>  THU Sep 14 19:24:07 UTC 2017