Solved Need to start a service rc script in jail after the assignment address net default gateway of the jail

Hello all,

In my journey of writing a rc.d script to start up an instance of Odoo ERP 18 Server on FreeBSD 14.2 Jail, when the Odoo jail starts up in order to connect to a postgreSQL database, the odoo service crashes with an error : Network is unreachable Is the server running on that host and accepting TCP/IP connections?.

And that is because the assignment of the address net default gateway of the jail is after the start-up of the Odoo rc.d script

The script works well when I execute it while being logged in on the Odoo jail, but at boot time or restarting the jail, I get the message described bellow.

So my question is how to make the assignment of the default gateway of the jail happen before the starting of the Odoo rc.d script
( Jail Boot ------> assignment of the default gateway ------> Starting-up Odoo rc.d script)

Code:
ELF ldconfig path: /lib /usr/lib /usr/lib/compat /usr/local/lib /usr/local/lib/compat/pkg /usr/local/lib/compat/pkg /usr/local/lib/perl5/5.36/mach/CORE
32-bit compatibility ldconfig path: /usr/lib32
Starting Network: lo0 epair233b.
lo0: flags=1008049<UP,LOOPBACK,RUNNING,MULTICAST,LOWER_UP> metric 0 mtu 16384
        options=680003<RXCSUM,TXCSUM,LINKSTATE,RXCSUM_IPV6,TXCSUM_IPV6>
        inet 127.0.0.1 netmask 0xff000000
        inet6 ::1 prefixlen 128
        inet6 fe80::1%lo0 prefixlen 64 scopeid 0x9
        groups: lo
        nd6 options=21<PERFORMNUD,AUTO_LINKLOCAL>
epair233b: flags=1008842<BROADCAST,RUNNING,SIMPLEX,MULTICAST,LOWER_UP> metric 0 mtu 1500
        options=8<VLAN_MTU>
        ether 02:7f:2d:60:7e:0b
        groups: epair
        media: Ethernet 10Gbase-T (10Gbase-T <full-duplex>)
        status: active
        nd6 options=29<PERFORMNUD,IFDISABLED,AUTO_LINKLOCAL>
add host 127.0.0.1: gateway lo0 fib 0: route already in table
add host ::1: gateway lo0 fib 0: route already in table
add net fe80::: gateway ::1
add net ff02::: gateway ::1
add net ::ffff:0.0.0.0: gateway ::1
add net ::0.0.0.0: gateway ::1
Clearing /tmp (X related).
Recovering vi editor sessions:.
Updating motd:.
Updating /var/run/os-release done.
Creating and/or trimming log files.
Starting syslogd.
odoo18ce configuration files are :
        odoo18ce_config   :  /usr/local/etc/odoo_erp/odoo18ce-server.conf
        odoo18ce_binfile  :  /usr/local/odoo_erp/odoo18ce/odoo18ce_server/odoo18ce-bin
        odoo18ce_python   :  /usr/local/bin/odoo18ce
Starting odoo18ce in 2 seconds.
Traceback (most recent call last):
  File "/usr/local/odoo_erp/odoo18ce/odoo18ce_server/odoo18ce-bin", line 8, in <module>
    odoo.cli.main()
  File "/usr/local/odoo_erp/odoo18ce/odoo18ce_server/odoo/cli/command.py", line 66, in main
    o.run(args)
  File "/usr/local/odoo_erp/odoo18ce/odoo18ce_server/odoo/cli/server.py", line 180, in run
    main(args)
  File "/usr/local/odoo_erp/odoo18ce/odoo18ce_server/odoo/cli/server.py", line 151, in main
    odoo.service.db._create_empty_database(db_name)
  File "/usr/local/odoo_erp/odoo18ce/odoo18ce_server/odoo/service/db.py", line 107, in _create_empty_database
    with closing(db.cursor()) as cr:
                 ^^^^^^^^^^^
  File "/usr/local/odoo_erp/odoo18ce/odoo18ce_server/odoo/sql_db.py", line 784, in cursor
    return Cursor(self.__pool, self.__dbname, self.__dsn)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/odoo_erp/odoo18ce/odoo18ce_server/odoo/sql_db.py", line 288, in __init__
    self._cnx = pool.borrow(dsn)
                ^^^^^^^^^^^^^^^^
  File "/usr/local/odoo_erp/odoo18ce/.local/lib/python3.11/site-packages/decorator.py", line 232, in fun
    return caller(func, *(extras + args), **kw)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/odoo_erp/odoo18ce/odoo18ce_server/odoo/tools/func.py", line 97, in locked
    return func(inst, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/odoo_erp/odoo18ce/odoo18ce_server/odoo/sql_db.py", line 712, in borrow
    result = psycopg2.connect(
             ^^^^^^^^^^^^^^^^^
  File "/usr/local/odoo_erp/odoo18ce/.local/lib/python3.11/site-packages/psycopg2/__init__.py", line 122, in connect
    conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
psycopg2.OperationalError: connection to server at "pg17db01.itlinker.local" (192.168.20.232), port 5432 failed: Network is unreachable
        Is the server running on that host and accepting TCP/IP connections?

Tried to start odoo18ce but could not obtain pid.
Starting cron.

Sun Jan 26 15:11:40 CET 2025
add net default: gateway 192.168.20.1
root@desktopfreebsd:~ #  
root@desktopfreebsd:~ #  
root@desktopfreebsd:~ # jls
   JID  IP Address      Hostname                      Path
    11                  pg17db01.itlinker.local       /usr/local/jails/containers/pg17db01
    13                  apache24web01.itlinker.local  /usr/local/jails/containers/apache24web01
    21                  odoo18erp01.itlinker.local    /usr/local/jails/containers/odoo18erp01
root@desktopfreebsd:~ #
 
I was looking at the rc script and was thinking something like this would do the trick:
Code:
odoo_start()
{
    sleep 5 ; daemon -p ${pidfile} -u ${odoo_user} \
                ${command} ${command_args}
                echo "Starting ${name}"
}

But if it doesn't work for you, you'll need to find something else.

What I don't understand is what can make a gateway so long to be reached?
 
I was looking at the rc script and was thinking something like this would do the trick:
Code:
odoo_start()
{
    sleep 5 ; daemon -p ${pidfile} -u ${odoo_user} \
                ${command} ${command_args}
                echo "Starting ${name}"
}

But if it doesn't work for you, you'll need to find something else.

What I don't understand is what can make a gateway so long to be reached?
I tested it with daemon, and the result was the same thing, I always got the Odoo rc script
starting before "add net default: gateway" of the jail.
 
Maybe you need to delay the jail startup to allow the host system to come up???
your-jail.conf
Code:
exec.start = "/bin/sleep 5";
exec.start += "/bin/sh /etc/rc";

Dan has a good somewhat related page to view:
I tested this hack, but the result is the same, I get the Odoo rc script starting before "add net default: gateway" of the jail.
In my case, the Odoo jail gets an IP @, and I can ping the outside world and install packages from freebsd.org.
 
Just add:
REQUIRES: NETWORKING

Or similar to your rc.d script. You may need to mess with different services where it starts. See rcorder.

Why not "prove" your script in /etc/rc.local then make it a service.
 
What about adding "REQUIRE: LOGIN" to your jails custom rc.d script?

Also consider /etc/rc.local for late starting scripts.
This is the start of the rc script

Code:
#!/bin/sh
# PROVIDE: odoo18ce
# REQUIRE: LOGIN NETWORKING daemon jail mountlate
# KEYWORD: shutdown
#
# Add the following lines to /etc/rc.conf to enable odoo18ce server
#
#
# odoo18ce_enable (bool): Set to "NO" by default,
#                         Set it to "YES" to enable odoo18ce server
#
# odoo18ce_config (str):  The path to the odoo18ce server configuration file
#                         (defaults to /usr/local/etc/odoo_erp/odoo18ce-server.conf")

. /etc/rc.subr

name="odoo18ce"
desc="Odoo ERP System Ver. 18.0, on netif vnet, @ 192.168.20.233 and port 8070"
procname="odoo18ce"
 
Just add:
REQUIRES: NETWORKING

Or similar to your rc.d script. You may need to mess with different services where it starts. See rcorder.

Why not "prove" your script in /etc/rc.local then make it a service.
I confirmed the order of the starting scripts like this:

Code:
Jail : [root@odoo18erp01:~] # rcorder /etc/rc.d/* /usr/local/etc/rc.d/*
.
........
/etc/rc.d/inetd
/etc/rc.d/syscons
/etc/rc.d/sshd
/etc/rc.d/sendmail
/etc/rc.d/cron
/etc/rc.d/jail
/etc/rc.d/bgfsck
/etc/rc.d/securelevel
/usr/local/etc/rc.d/odoo18ce
Jail : [root@odoo18erp01:~]

As you can see, the Odoo rc script is the later .
 
I see a list for REQUIRES: as pointless.

Pick the latest starting one.
LOGIN means it won't fire off until a login prompt is presented. Usually very late in process.
 
OK so the starting order looks good so you need to add some sleep. What about netwait in the jail? Have you tried that?
I tested to delay the jail with this hack but without success :
Code:
exec.start = "/bin/sleep 5";
exec.start += "/bin/sh /etc/rc";

What is the config of netwait in the jail ?
 
The prototype file /etc/defaults/rc.conf has the options. Either an ip based approach or interface based one.

Code:
### Network link/usability verification options
netwait_enable="NO"        # Enable rc.d/netwait (or NO)
#netwait_ip=""            # Wait for ping response from any IP in this list.
netwait_timeout="60"        # Total number of seconds to perform pings.
#netwait_if=""            # Wait for active link on each intf in this list.
netwait_if_timeout="30"        # Total number of seconds to monitor link state.

This will go in your Jails /etc/rc.conf. Do not edit or modify the defaults file.

Dans page above has an Interface based approach to netwait for jails.
 
I am sorry Dans example has both IP(v6) and Interface based settings so trim to something like this:

Jails /etc/rc.conf
Code:
netwait_enable="YES"
netwait_if="igb0" <<<< Your Jails Interface Name Here<<<<<
netwait_if_timeout="60"
 
Good morning all,

Thank you, Phishfry for your help and time, the config you suggested work well, and I have made my Odoo rc script operate after the assignment of the default gateway IP @.
And to achieve my goal, I had to configure the assignment of the default gateway and the IP @ of the jail inside {/etc/rc.conf[Jail Odoo]}, so the config is like this :
Code:
Jail : [root@odoo18erp01:~] # 
Jail : [root@odoo18erp01:~] # cat /etc/rc.conf
# Need to start a service rc script in jail after the assignment address net default gateway of the jail
# how to make the assignment of the default gateway of the jail happen before the starting of the Odoo rc.d script
# ( Jail Boot ------> assignment of the default gateway ------> Starting-up Odoo rc.d script)
ifconfig_epair233b="inet 192.168.20.233/24 up"
defaultrouter="192.168.20.1"
netif_enable="YES"                              # Set to YES to initialize network interfaces
netwait_enable="YES"                            # Enable rc.d/netwait (or NO)
netwait_ip="192.168.20.1 192.168.20.232"        # Wait for ping response from any IP in this list.
netwait_if="epair233b"                          # Wait for active link on each intf in this list.

# Start Odoo ERP Server 
odoo18ce_enable="YES"
odoo18ce_config="/usr/local/etc/odoo_erp/odoo18ce-server.conf"
Jail : [root@odoo18erp01:~] #

G01 - Need to start a service rc script in jail after the assignment address net default gatew...png


And below the config of the vnet interface on the host in {/etc/jail.conf.d/odoo18erp01.conf[host]} :

G02 - Need to start a service rc script in jail after the assignment address net default gatew...png


Thanks to all the community FreeBSD, and specially to the people of this forum.
 
Back
Top