Skip to content
Kobolog edited this page Dec 1, 2012 · 5 revisions
  1. Requirements
  2. Package description
  3. Installation from packages
    • [Linux (Debian и Ubuntu)] (#linux-debian)
    • Mac OS X
  4. Building and installing from source code
  5. Running the Cocained server
  6. Configuration file of the Cocained server
  7. Configuration file of the Cocaine Dealer

Requirements

Supported operating systems:

  • Linux (Debian and Ubuntu)
  • Mac OS X

Packages description

Basic server installation includes the following packages:

  • cocaine-generic-slave — standard sandbox to run the application;
  • cocaine-server — the core of the cloud platform;
  • cocaine-tools — with this set of tools you can manage the server part;
  • libcocaine-common1 — common components for the platform;
  • libcocaine-core1 — server components of the platform.

If you need to extend the functionality of the Cocained for specific tasks you can use the following plugins:

  • libcocaine-plugin-dealer — a plugin to allow the server to work with the Cocaine Dealer;
  • libcocaine-plugin-python — Python language support;
  • libcocaine-plugin-perl — Perl language support;
  • libcocaine-plugin-binary — a plugin to allow the server to load compiled binary apps;
  • libcocaine-plugin-chrono — a plugin to allow the server to run timed tasks;
  • libcocaine-plugin-fs — a plugin to allow the server to run tasks based on the events in the filesystem;
  • libcocaine-plugin-elliptics — adds an ability to work with the data storage Elliptics;
  • libcocaine-plugin-mongodb — adds an ability to work with the data storage MongoDB.

Installation from packages

Linux (Debian and Ubuntu)

Most of the dependencies can be pulled in with a single command:

$ sudo apt-get install build-essential cmake libboost-thread-dev libboost-filesystem-dev \
libboost-program-options-dev libzmq-dev libmsgpack-dev libev-dev libltdl-dev libssl-dev \
uuid-dev libarchive-dev libssl-dev

MongoDB C++ Driver is not included in the default repositories for Ubuntu or Debian, so you have to manually build and install it. There're instructions in place at the MongoDB Website on that matter.

Mac OS X

We recommend using Homebrew to ease the installation of the required dependencies. In order to install all the required stuff (except MongoDB C++ Driver, sadly), type the following commands in your Terminal:

$ brew install pkg-config
$ brew install boost cmake zeromq msgpack libev libtool

You can get header files for the libarchive library from the Apple Opensource site.

In order to build the MongoDB C++ Drivers, you'll also need the SCons build system:

$ brew install scons

After that, simply follow the instructions on the MongoDB Website.

Cocaine daemon requires presence of folder /var/run/cocaine with read and write access.

Building and installing from source code

Generally, you need to have some prerequisites installed to build the server, although some of them might be already bundled with your operating systems. These prerequisites are:

Also, you'll need some additional dependencies to build the optional modules:

As of now, you should have all the prerequisites in place already, so just pull the source code of Cocained from GitHub and build it:

$ git clone git://github.com/cocaine/cocaine-core.git
$ cd cocaine-core
$ cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_INSTALL_PREFIX=/usr/local -DELLIPTICS=NO -DMONGO=NO
$ make
$ sudo make install

If you have the dependencies installed in some non-standard places, you can specify them by editing the CMakeCache.txt file generated by the CMake build system, or install the ccmake (which might be already installed together with CMake, which is the case on Mac), which is a Curses interface to CMake and edit the build settings in a more-or-less user-friendly interface. The options are mostly self-explainable, for example, LIBMSGPACK_INCLUDE_DIRS specify where the development headers for MessagePack are installed.

Running the Cocained server

After installation from the packages

After installation from the packages Cocained will run as a daemon with the following parameters:

$ cocained tcp://*:5000 --daemonize --pidfile /var/run/cocaine/cocained.pid --configuration /etc/cocaine/cocaine.conf

Configuration file of the Cocained server will be located in a file called /etc/cocaine/cocaine.conf.

By default, the logs will be saved with the syslog-ng daemon to the file /var/log/cocaine-core/cocained.log and the configuration file for syslog-ng will be located in the file /etc/syslog-ng/conf-available/cocained.conf

After installing from the source code

Every possible command-line option is described in the built-in command line help, which you can see by typing the following command in your Terminal:

$ cocained --help

To start the Server with some kind of a basic configuration, use the following command line:

$ sudo cocained tcp://*:5000 --verbose

This will start the server listening for RPC calls on all interfaces on port 5000, using the default configuration file located in /etc/cocaine/default.json. All the information will go to the syslog, so look there if something goes south.

The default configuration file should look somewhat like this:

{
    "version": 1,
    "paths": {
        "plugins": "/usr/lib/cocaine",
        "ipc": "/var/run/cocaine",
        "spool": "/var/spool/cocaine"
    },
    "storages": {
        "core": {
            "type": "files",
            "args": {
                "path": "/var/lib/cocaine"
            }
        },
        "core:cache": {
            "type": "files",
            "args": {
                "path": "/var/cache/cocaine"
            }
        }
    }
}

Configuration file of the Cocained server

Configuration file of the Cocaine Dealer

The configuration file is required to create a dealer_t object. This is a plain text file in JSON format with the following structure:

{
        "version" : int,
        "use_persistense" : bool,
        "logger" : {},
        "persistent_storage" : {},
        "services" : {}
}

This is description for each sections of the configuration file:

  • Simple variables

    • version (mandatory variable) — version of the configuration file;
    • use_persistense (not mandatory variable) — activation flag of the persistent queue (default - false).

* **Logger** (not required section)

This section describes the settings of logging and looks like this:

        "logger" :
        {
                "type" : str,
                "flags" : str
        }

Cocaine Dealer supports several types of logging: logging in stdout, file or syslog. The type of logging can be specified by setting the variable type one of the following strings values:

  • "FILE_LOGGER"
  • "SYSLOG_LOGGER"
  • "STDOUT_LOGGER" (the default value if the variable type is not specified at all).

Variable flags contains a string in which a specified combination of filter flags of logging. Valid flags:

  • PLOG_NONE - logging is off;
  • PLOG_INFO - to display logs with level INFO;
  • PLOG_DEBUG - to display logs with level DEBUG;
  • PLOG_WARNING - to display logs with level WARNING;
  • PLOG_ERROR - to display logs with level ERROR;
  • PLOG_TYPES - to display the types of records in the log;
  • PLOG_TIME - to display the times of records in the log;
  • PLOG_INTRO - to display the head of the log;
  • PLOG_BASIC — t’s a combination of the following flags: PLOG_TYPES, PLOG_TIME and PLOG_INFO;
  • PLOG_ALL — it’s a combination of the following flags: PLOG_TYPES, PLOG_TIME, PLOG_INFO, PLOG_DEBUG, PLOG_WARNING and PLOG_ERROR.

The combinations of flags are listed on the same line separated by vertical bars, for example:

"flags" : "PLOG_INTRO | PLOG_INFO"

Types of loggers:

  • STDOUT_LOGGER - the default and does not require additional configuration;
  • FILE_LOGGER - used to write the log to a file and requires an additional parameter «file», in which indicates the path to the file to be written log.

An example:

"logger" :
            {
                "type" : "FILE_LOGGER",
                "flags" : "PLOG_INTRO | PLOG_INFO",
                "file" : "/var/log/dealer.log"
            },
  • SYSLOG_LOGGER - using to write logs to syslog and requires an additional parameter «identity» which indicates ident in syslog which will be written log.

An example:

"logger" :
            {
                "type" : "SYSLOG_LOGGER",
                "flags" : "PLOG_INTRO | PLOG_INFO",
                "identity" : "my_dealer_log"
            },		

By default the logging is turned off.

  • Persistent_storage (not required section)

This section lists the local storage settings for persistent queue of messages (or, in other words, the queue of messages automatically cached in the local storage) - eblob. The following settings:

  • eblob_path - the path to the storage directory;
  • blob_size - size of blob (in bytes);
  • sync_interval - sync interval of page-cache on the hard disk (in seconds);
  • thread_pool_size - size of the pool of threads to read / write data;
  • defrag_timeout - speed of defragmentation storage (in seconds).

Section example:

"persistent_storage" :
    {
        "eblob_path" : "/var/tmp/eblobs",
        "blob_size" : 2048,
        "sync_interval" : 0,
        "thread_pool_size" : 4,
        "defrag_timeout" : 600
    },
  • Services (mandatory section)

This section lists the applications in the cloud, which are going to interact with users. Applications are listed as follows:

"services" :
    {
        "app_alias_1" : {
        },
        "app_alias_2" : {
        },
        "app_alias_3" : {
        }
    }

app_alias_1, app_alias_2 и app_alias_3 — aliases of applications that meet certain settings.

Description of one service:

"app_alias" : {
        "app" : "my_app",
        "autodiscovery" : {
            "source" : "/etc/cocaine/my_app_hosts",
            "type" : "FILE"
        }
    }

app_alias is an alias for the application that the appropriate settings:

  • app - the name of the application in the cloud;
  • autodiscovery/source - the data source that lists the host on which the application is deployed, in this case, "/etc/cocaine/my_app_hosts". A data source can serve as a local file or HTTP URL;
  • autodiscovery/type - the type of data source can be set to FILE and HTTP.

Section example:

"services": {
    "my_app_alias_A" : {
        "app" : "my_app",
        "autodiscovery" : {
            "source" : "/etc/cocaine/app_hosts",
            "type" : "FILE"
    },
    "my_app_alias_B" : {
        "app" : "my_other_app",
        "autodiscovery" : {
            "source" : "http://somehost/app_hosts",
            "type" : "HTTP"
    }
}

Please note that in configuration file have to be written the parameter «version» with the version of the configuration file and at least one service.