I want to write lua daemon that listens to TCP socket and allows to handle some user data. I'm using copas library to make my server works with multiply clients simultaneously, but don't know how to daemonize this server. It seems copas doesn't provide such functionality. Does anybody know how to create daemon process in Lua?
Here is a part of code where I define my server:
function handler(c, host, port)
local peer = host .. ":" .. port
print("connection from ", peer)
while 1 do
command = c:receive"*l"
c:send(router(command))
end
end
copas.addserver(assert(socket.bind("127.0.0.1", 8888)),
function(c) return handler(copas.wrap(c), c:getpeername()) end
)
copas.loop()
Thanks in advance!