Chapter 3. A.L.E.C's LMS Daemon

3.1. Basics

Written in C program facilitate management of services. Daemon is responsible for starting of appropriate modules on user demand only. Modules are making configuration files based on data from LMS's database and restarting selected services on a server.

Why such name? The better part of daemon code was written by one of developers - Aleksander 'A.L.E.C' Machniak, nevertheless must underline a contribution of Marcina 'Lexx' Krol. Program include fragments of code of Mateusza 'mteg' Golicz's old daemon and use Nicolas Devillard's iniparser library.

3.1.1. Requirements

A.L.E.C's LMS Daemon require:

  • LMS user interface installation

  • libmysqlclient (full MySQL installation or respective packet) or libpq in case of PostgreSQL database or sqlite

  • libdl (that is in every present-day distribution)

  • C compiler

3.1.2. Installation

Prior to compilation you must set options described on following listing with help of ./configure script (in brackets are shown default values):

  --help                help
  --enable-debug0       SQL queries logging (disabled)
  --enable-debug1       events logging (disabled)
  --with-pgsql          enables using of PostgreSQL database (disabled)
  --with-mysql          enables using of MySQL database (enabled)
  --with-sqlite         enables using of SQLite database (disabled)
  --prefix=DIR          program install directory (/usr/local/bin)
  --libdir=DIR          location of database libraries (/usr/lib)
  --incdir=DIR          location of database header files (/usr/include)
Then, required is to set database which you will use (--with-mysql or --with-pgsql) and location of libraries supplied with database (--incdir, --libdir). You can use only one database. If you will change database, you must to recompile daemon.
# ./configure --with-pgsql --libdir=/usr/local/pgsql/lib --incdir=/usr/local/pgsql/include
After that you can compile and install (put daemon in directory given with --prefix option):
# make && make install
Finally, compiled modules (files with .so extension), found in directory modules/module_name move to any directory. Their location you will set in configuration file.

3.1.3. Configuration

Example daemon configuration you can find in file lms.ini.sample. Following listing describe basic options for daemon (modules configuration is described in separate chapters concerning modules):

[database]
host            = localhost     # host name or IP, default: localhost
user            = lms           # user name, default: lms
password        = mypasswd      # database password, default: empty
database        = lms           # database name, default: lms
port            = 0             # port number, default: 0

[lmsd]
sleeptime       = 30            # time interval (in seconds) how often to
                                # check for reload order, default: 30
instances       = hosts oident firewall       # module instances list
command         = 'echo Connecting...'        # shell command to run before every database connection 
Note

List of instances contains instances names detached with spaces. Instance is a name of section in configuration file.

In instance section, beside config modules params, you must specify primary options, as on following listing:

[instance_name]
module = /path/to/module.so
info = "Additional description of module"

Change of 'instances' and any option i instances sections do not require daemon restart. For other global options restart is required.

3.1.4. Starting

You can run program as a daemon working in background (option '-b'). Then configuration and services reload is done on demand with use of 'Reload' menu in LMS-UI. Option 'sleeptime' (-s) specify interval between database reads. When daemon detects reload order, he runs modules defined by 'instances' option in lms.ini. For example:

# almsd -b

Other way to run is disposable reload with usage of cron. You must to use this manner of reload for runing modules like 'payments' 'notify' or 'traffic'. In that case you can specify instances to reload with use of option '-i'. Example crontab's entry:

  1 0 * * *    /usr/local/bin/almsd -qi "payments notify"

Following listing describe program command line options:

  -c     path to config (default: /etc/lms/lms.ini)
  -i     list of instances (separated by space) to reload
  -b     run in background (daemon mode)
  -s     'reload' table reading interval in sec. (default: 30)
  -q     reload and quit
  -h     prints command line options