Service runs with su, not with daemon

Greetings,

Hopefully I am posting in the right place, if not please let me know!

The goal is to run a python framework (odoo) as a service via daemon inside a jail. The topology is as follows:

[Internet] --> [Host] -- (pf)--> [Jail with HAProxy] --> [Jail with Odoo]

For reference, I am using vnet with epairs and a bridge. Only the host has pf rules, very simple setup to perform NAT and port forwarding.

I have downloaded the framework and got it to run after a bit of tinkering, to start it I run the command:

su -l odoo -c '/usr/local/odoo/odoo-bin -c /usr/local/etc/odoo.conf'

At this point I can see in the application log that everything was loaded correctly and I can access the application from within the jail ( fetch -qo - http://127.0.0.1:8069), from the HAProxy jail and also from my web browser through the internet.

So at this point all is good. The application is running, the network is working, the only thing missing is turning the application into a service with daemon.

I found an existing rc.d/odoo file which I have modified slightly, here it is for reference:

Bash:
#!/bin/sh

# PROVIDE: odoo
# REQUIRE: DAEMON postgresql
# KEYWORD: shutdown

. /etc/rc.subr

name=odoo
rcvar=odoo_enable

procname="python3.7"
pidfile="/var/run/odoo/${name}.pid"
logfile="/var/log/odoo/${name}.log"

load_rc_config $name
: ${odoo_conf_path:="/usr/local/etc/odoo.conf"}

command="/usr/sbin/daemon"
command_args="-u odoo /usr/local/odoo/odoo-bin -c ${odoo_conf_path} --pidfile=${pidfile} --logfile=${logfile}"

run_rc_command "$1"

And this is where the problems begin. Although the service starts, it seems that it either hangs or it is not receiving requests at all.

I tried to narrow down the issue by starting the application with the following command:

/usr/sbin/daemon -u odoo /usr/local/odoo/odoo-bin -c /usr/local/etc/odoo.conf

Basically the same as thing as it was (successfully) done with the su command, but this time I get no reply from the server.

First of all, I reckon that the rc.d/odoo definition is not perfect and can be improved but shouldn't this work when running it through daemon?

I ran tcpdump from within the jail and I see the request arriving to the internal interface, but no activity at all in the application. Any ideas or suggestions on what to try? I don't know if I am missing something very obvious here.

Thank you for the assistance!
 
daemon(8) can be used only for launching processes which don’t daemonize itself. I don’t know odoo, therefore my question. When you start it with su, is it kept as a foreground process, or does it go into the background and you are back on the command line immediately?

In the latter case, you won’t use daemon for starting odoo, but launch it directly in your rc-script, see below. Alternatively, most daemons got a command line switch for keeping it in the foreground, and with this switch in place you may use daemon for launching. For example Apache's httpd(8) got two switches -DNO_DETACH and -DFOREGROUND, and with this, httpd could be launched with daemon.

I would also change the requirements from DAEMON to LOGIN.

Bash:
#!/bin/sh

# PROVIDE: odoo
# REQUIRE: LOGIN postgresql
# KEYWORD: shutdown

. /etc/rc.subr

name=odoo
rcvar=odoo_enable

procname="python3.7"
pidfile="/var/run/odoo/${name}.pid"
logfile="/var/log/odoo/${name}.log"

load_rc_config $name
: ${odoo_conf_path:="/usr/local/etc/odoo.conf"}
: ${odoo_user="odoo"}

command="/usr/local/odoo/odoo-bin"
command_args="-c ${odoo_conf_path} --pidfile=${pidfile} --logfile=${logfile}"

run_rc_command "$1"
 
Greetings obsigna, thanks for the reply.

odoo is just a python application, when I start it with su it stays in the foreground, hence my idea of using daemon(), I think this would be the preferred approach, no?
 
Back
Top