Giter Club home page Giter Club logo

lapis-systemd's Introduction

lapis-systemd

lapis-systemd is a lapis extension that lets you create systemd service files for your websites and log to the systemd journal easily.

Install

$ luarocks install lapis-systemd

Creating service files

You can use the new systemd command to generate service files for different environments. From your shell:

$ lapis systemd service development

Will generate a file in the current directory, named after your app: some-app-development.service

The contents might look like this:

[Unit]
Description=some-app development
After=network.target

[Service]
Type=simple
PIDFile=/home/leafo/code/sites/itch.io/logs/nginx.pid
Environment='LUA_PATH=;;/home/leafo/.luarocks/share/lua/5.1/?.lua;/home/leafo/.luarocks/share/lua/5.1/?/init.lua' 'LUA_CPATH=;;/home/leafo/.luarocks/lib/lua/5.1/?.so'
WorkingDirectory=/home/leafo/code/sites/itch.io
ExecStart=/home/leafo/.luarocks/bin/lapis server development
ExecReload=/home/leafo/.luarocks/bin/lapis build development

[Install]
WantedBy=multi-user.target

Note that the path of your project is hard-coded into the service, along with the path of the lapis binary and any Lua environment variables. If you ever move the project around or reconfigure your system you should regenerate the service file.

Since these paths are specific to a machine, it's not recommended to check the service files into your respository.

You can generate and install the service file to the system with the following command: (Do not run this command with sudo, it will call sudo for you when copying the necessary file.)

$ lapis systemd service development --install

You can then start your service:

$ sudo systemctl start some-app-development

And view the logs for it:

$ sudo journal -u some-app-development

Configuring service file

The systemd entry in your lapis config can be used to control how the service file is generated:

-- config.lua
local config = require("lapis.config")

config("production", {
  systemd = {
    user = "leafo" -- service will run as user
  }
})

If you want to enable journal log writes (when using the log function in lapis.systemd.journal) then you can set journal = true in systmed config block:

-- config.lua
local config = require("lapis.config")

config("production", {
  systemd = {
    user = "leafo",
    journal = true
  }
})

Writing to logs

You can access the systemd journal with the lapis.systemd.journal module:

journal = require("lapis.systemd.journal")
journal.log("hello world!", {priority = 5})

lapis-systemd's People

Contributors

leafo avatar tangentfoxy avatar

Watchers

 avatar  avatar

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.