I
I
Ivan2016-11-14 15:21:53
linux
Ivan, 2016-11-14 15:21:53

How to create your own daemon in centos 7 on lua?

Good afternoon.
There is a lua script that connects to the server and in a loop, while there is a connection, it waits for an event and already does the necessary processing.
Approximately like this

#!/usr/local/bin/lua

local con = Connetct(url, login, pass);

if con:connected() then
   #обработка
end

To run this script as a daemon I use systemd. I got this config
[Unit]
Description=lvCallCenter
After=mysql.service
Requires=mysql.service

[Service]
Type=forking
PIDFile=pid
WorkingDirectory=dir

User=leadvertex
Group=leadvertex

Environment=RACK_ENV=production

OOMScoreAdjust=-1000

ExecStart=/usr/local/bin/lua script.lua
Restart=always
TimeoutSec=300

[Install]
WantedBy=multi-user.target

It starts a little differently than we would like, i.e. after starting the systemctl start myunit command, nothing happens, no conclusion that everything has started and you have to press ctrl + c to cancel.
But the daemon appears in the processes and everything works.
But I would like to make it run normally.
Most likely the problem is in the output streams, I tried to redefine them, it did not help. I also think that the lua script should somehow answer systemd that it has started and is working.
Please help me to solve this issue. Thank you in advance for your help.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
ipc_ngs, 2016-11-14
@kalashnikofff

You have "Type=forking" specified, which is used for services that start themselves in the background. Your script does not. So remove "Type=forking", or replace it with the default value "Type=simple".

E
elcanner, 2016-11-14
@elcanner

Not a specialist in systemd and especially in lua. But "running demons" has always helped me with such a crutch as screen :)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question