Code Monkey home page Code Monkey logo

tarantool-appstarter's Introduction

THIS PROJECT IS NO LONGER SUPPORTED. PLEASE USE moonlibs/tarantoolapp

tarantool-appstarter

Tarantool application starter

Requirements

  • tarantool >= 1.6
  • luarocks (for lua 5.1)

Run

Clone and run

bin/tntstartapp /path/to/app

You can add bin/ folder to your PATH variable to run in arbitrary directory:

cd /path/to/my/app
tntstartapp .

Rationale

The main idea behind this appstarter is to provide you with a default approach of developing apps for Tarantool. To create a project starter you can run

mkdir -p /path/to/app
tntstartapp /path/to/app

And you'll end up with a default structure of an app. There are some important parts in it:

  1. dep.lua and meta.yaml. Luarocks spec files does not support specifying dependencies on GH projects (via link to *.rockspec file), but the luarocks itself does. So, meta.yaml is a place where you drop your external dependencies (like a package.json for npm or requirements.txt for pip). You can specify either tarantool modules there (in the tntdeps section) by there names (like queue or http) or just bare links to *.rockspec files (in the deps section). Then a bundled dep.lua script will use this meta.yaml file to install all the required dependencies to a specified location.
  2. Makefile. There are 2 main commands there:
  • make dep - This command installs all the dependencies from meta.yaml to a local folder .rocks inside your project (already in bundled .gitignore)
  • make run. After a successful installation of dependencies you can run your application. Practically it just creates a temporary folder .tnt_{LISTEN_URI}, cd's inside and runs tarantool init.lua.
  1. init.lua - An entry point to your entire application. Specifically, it does this:
  • patches package.path and package.cpath to import packages from ./.rocks and ./app folders directly.
  • require's package.reload module
  • require's config module (please refer to @mons's tnt-config module for more details). By default (if not specified in ENV variable CONF) it uses config file from /etc/{your_app_name}/conf.lua
  • Runs require('app'). Which is essentially is run of your application.
  • Also it starts the interactive console immediately (so you don't need to explicitly connect to your Tarantool instance)
  1. app. This is a directory that contains all of your application code. It is absolutely up to you how you organize your code in this folder. By default app/init.lua require's your inner application module and registers in the package-reload module. So when code reload happens, the destroy function of your module is called (to cleanup resources, stop fibers or whatever you want).

Project deploy structure

The recommended way to deploy apps with tarantool-appstarter is to the following file structure:

/
├── etc
│   └── {{__appname__}}
│       └── conf.lua
└── usr
    └── share
        └── {{__appname__}}
            ├── init.lua
            ├── app/
            └── .rocks/

As you can see, init.lua, app folder and .rocks folder (so you, obviously, need to bundle your dep or rpm package with your dependencies) deploy to /usr/share/{appname}/, and conf.lua deploys to /etc/{appname}/conf.lua.

In order to run your applcation by either tarantoolctl or systemd you need to do the following:

  • put a symlink /etc/tarantool/instances.enabled/{appname}.lua -> /usr/share/{appname}/init.lua.
  • execute either tarantoolctl start {appname} or systemctl start tarantool@appname.

Hot-reload

After all of that, if you want to hot-reload your application you just deploy your new code, connect to your running instance by any preferred method (for example, by executing tarantoolctl enter {appname}) and run package.reload(). That should be it.

tarantool-appstarter's People

Contributors

igorcoding avatar mons avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Forkers

mons ochaton kn666

tarantool-appstarter's Issues

Mons config module not reloaded on hot reload

I added new tarantool options like memtx_* to tnt-config - https://github.com/ddosoff/tnt-config/blob/master/config.lua

Update your config-scm-1.rockspec to point this repo in meta.yaml.

Options not updated with package.reload():

2017-03-29 20:39:52.090 [10117] main/682/console/127.0.0.1:40050 I> 9th load. Unloading {chatbro, web_connections, tomcat_sessions, app, bench, lib, config, id, pg.driver, pg_import, users, pg}
2017-03-29 20:39:52.090 [10117] main/682/console/127.0.0.1:40050 I> package.reload:cleanup...
2017-03-29 20:39:52.100 [10117] main/682/console/127.0.0.1:40050 I> Removing trigger: web_connections_trigger
2017-03-29 20:39:52.100 [10117] main/682/console/127.0.0.1:40050 I> Truncate counters: web_connections_totals
2017-03-29 20:39:52.101 [10117] main/682/console/127.0.0.1:40050 I> Goodbye from chatbro
2017-03-29 20:39:52.101 [10117] main/682/console/127.0.0.1:40050 I> package.reload:cleanup finished
2017-03-29 20:39:52.104 [10117] main/682/console/127.0.0.1:40050 config.lua:158 E> Parameter 'box.checkpoint_count' = '20' is not a valid configuration option. Mask it with local, if it's a mistake
2017-03-29 20:39:52.104 [10117] main/682/console/127.0.0.1:40050 config.lua:158 E> Parameter 'box.memtx_memory' = '2147483648' is not a valid configuration option. Mask it with local, if it's a mistake
2017-03-29 20:39:52.104 [10117] main/682/console/127.0.0.1:40050 config.lua:158 E> Parameter 'box.checkpoint_interval' = '14400' is not a valid configuration option. Mask it with local, if it's a mistake

But it works on tarantool restart.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.