Netbox Service Timeout | Unable to start Netbox.service

Hey there!

I really like Nix and NixOS. And up until now everything was more or less straightforward. Last week however, I stumbled upon an issue I’m still not able to overcome thus asking for some ideas or directions on how to solve it.

Issue
I want to host a Netbox-Server on a NixOS machine. Thus I use the NixOS-Module with the recommended standard configuration from here NetBox - NixOS Wiki .

The Nginx-Proxy works but delivers a 502 - Bad Gateway Error. After investigating it turns out, that the Netbox.service unit gets terminated due to a timeout issue. I can’t figure out why it does so.

Any ideas on how I can get Netbox up and running?

What is the expected outcome?
Starting netbox.service and reaching the Netbox Webinterface.

What output did you get?
If I connect to the Webinterface I get a Server Error with Error Code 502 - Bad Gateway.
Systemctl shows that the Netbox.service Unit got terminated with Status Code 15.

What did I already try to solve the issue?

  • Systemctl restart netbox.service.
  • Restarting the system.
  • Nix-collect-garbage -d.
  • Changing Netbox dataDir to /opt/netbox and running chmod -R 777 && chown -R netbox:netbox in order to check if permission issues could be at play (I do not intend on using it that way).

Meta information like system and nix versions

Output of “systemctl status netbox”

● netbox.service - NetBox WSGI Service
     Loaded: loaded (/etc/systemd/system/netbox.service; enabled; preset: enabled)
     Active: activating (auto-restart) (Result: timeout) since Mon 2024-03-04 09:20:21 UTC; 26s ago
       Docs: https://docs.netbox.dev/
    Process: 2382 ExecStartPre=/nix/store/7qg8y193x0sxd4ykq20zspk5xlqkv6lg-unit-script-netbox-pre-start/bin/netbox-pre-start (code=killed, signal=TERM)
         IP: 22.3K in, 11.1K out
        CPU: 26.747s

Mar 04 09:20:21 01SVLBKP01 systemd[1]: netbox.service: Consumed 26.747s CPU time, received 22.3K IP traffic, sent 11.1K IP traffic.

Output of “journalctl -xeu netbox.service”

Mar 04 09:12:02 01SVLBKP01 netbox-pre-start[2303]:   dcim.inventoryitem... No objects found.
Mar 04 09:12:02 01SVLBKP01 netbox-pre-start[2303]:   dcim.location... No objects found.
Mar 04 09:12:02 01SVLBKP01 netbox-pre-start[2303]:   dcim.manufacturer... No objects found.
Mar 04 09:12:02 01SVLBKP01 netbox-pre-start[2303]:   dcim.module... No objects found.
Mar 04 09:12:02 01SVLBKP01 netbox-pre-start[2303]:   dcim.modulebay... No objects found.
Mar 04 09:12:02 01SVLBKP01 netbox-pre-start[2303]:   dcim.moduletype... No objects found.
Mar 04 09:12:02 01SVLBKP01 netbox-pre-start[2303]:   dcim.platform... No objects found.
Mar 04 09:12:02 01SVLBKP01 netbox-pre-start[2303]:   dcim.powerfeed... No objects found.
Mar 04 09:12:02 01SVLBKP01 netbox-pre-start[2303]:   dcim.poweroutlet... No objects found.
Mar 04 09:12:02 01SVLBKP01 netbox-pre-start[2303]:   dcim.powerpanel... No objects found.
Mar 04 09:12:02 01SVLBKP01 netbox-pre-start[2303]:   dcim.powerport... No objects found.
Mar 04 09:12:02 01SVLBKP01 netbox-pre-start[2303]:   dcim.rack... No objects found.
Mar 04 09:12:02 01SVLBKP01 netbox-pre-start[2303]:   dcim.rackreservation... No objects found.
Mar 04 09:12:02 01SVLBKP01 netbox-pre-start[2303]:   dcim.rackrole... No objects found.
Mar 04 09:12:02 01SVLBKP01 netbox-pre-start[2303]:   dcim.rearport... No objects found.
Mar 04 09:12:02 01SVLBKP01 netbox-pre-start[2303]:   dcim.region... No objects found.
Mar 04 09:12:02 01SVLBKP01 netbox-pre-start[2303]:   dcim.site... No objects found.
Mar 04 09:12:02 01SVLBKP01 netbox-pre-start[2303]:   dcim.sitegroup... No objects found.
Mar 04 09:12:02 01SVLBKP01 netbox-pre-start[2303]:   dcim.virtualchassis... No objects found.
Mar 04 09:12:02 01SVLBKP01 netbox-pre-start[2303]:   dcim.virtualdevicecontext... No objects found.
Mar 04 09:12:02 01SVLBKP01 netbox-pre-start[2303]:   ipam.aggregate... No objects found.
Mar 04 09:12:02 01SVLBKP01 netbox-pre-start[2303]:   ipam.asn... No objects found.
Mar 04 09:12:02 01SVLBKP01 netbox-pre-start[2303]:   ipam.asnrange... No objects found.
Mar 04 09:12:02 01SVLBKP01 netbox-pre-start[2303]:   ipam.fhrpgroup... No objects found.
Mar 04 09:12:02 01SVLBKP01 netbox-pre-start[2303]:   ipam.ipaddress... No objects found.
Mar 04 09:12:02 01SVLBKP01 netbox-pre-start[2303]:   ipam.iprange... No objects found.
Mar 04 09:12:02 01SVLBKP01 netbox-pre-start[2303]:   ipam.l2vpn... No objects found.
Mar 04 09:12:02 01SVLBKP01 netbox-pre-start[2303]:   ipam.prefix... No objects found.
Mar 04 09:12:02 01SVLBKP01 netbox-pre-start[2303]:   ipam.rir... No objects found.
Mar 04 09:12:02 01SVLBKP01 netbox-pre-start[2303]:   ipam.role... No objects found.
Mar 04 09:12:02 01SVLBKP01 netbox-pre-start[2303]:   ipam.routetarget... No objects found.
Mar 04 09:12:02 01SVLBKP01 netbox-pre-start[2303]:   ipam.service... No objects found.
Mar 04 09:12:02 01SVLBKP01 netbox-pre-start[2303]:   ipam.servicetemplate... No objects found.
Mar 04 09:12:02 01SVLBKP01 netbox-pre-start[2303]:   ipam.vlan... No objects found.
Mar 04 09:12:02 01SVLBKP01 netbox-pre-start[2303]:   ipam.vlangroup... No objects found.
Mar 04 09:12:02 01SVLBKP01 netbox-pre-start[2303]:   ipam.vrf... No objects found.
Mar 04 09:12:02 01SVLBKP01 netbox-pre-start[2303]:   extras.journalentry... No objects found.
Mar 04 09:12:02 01SVLBKP01 netbox-pre-start[2303]:   tenancy.contact... No objects found.
Mar 04 09:12:02 01SVLBKP01 netbox-pre-start[2303]:   tenancy.contactgroup... No objects found.
Mar 04 09:12:02 01SVLBKP01 netbox-pre-start[2303]:   tenancy.contactrole... No objects found.
Mar 04 09:12:02 01SVLBKP01 netbox-pre-start[2303]:   tenancy.tenant... No objects found.
Mar 04 09:12:02 01SVLBKP01 netbox-pre-start[2303]:   tenancy.tenantgroup... No objects found.
Mar 04 09:12:02 01SVLBKP01 netbox-pre-start[2303]:   virtualization.cluster... No objects found.
Mar 04 09:12:02 01SVLBKP01 netbox-pre-start[2303]:   virtualization.clustergroup... No objects found.
Mar 04 09:12:02 01SVLBKP01 netbox-pre-start[2303]:   virtualization.clustertype... No objects found.
Mar 04 09:12:02 01SVLBKP01 netbox-pre-start[2303]:   virtualization.virtualmachine... No objects found.
Mar 04 09:12:02 01SVLBKP01 netbox-pre-start[2303]:   virtualization.vminterface... No objects found.
Mar 04 09:12:02 01SVLBKP01 netbox-pre-start[2303]:   wireless.wirelesslan... No objects found.
Mar 04 09:12:02 01SVLBKP01 netbox-pre-start[2303]:   wireless.wirelesslangroup... No objects found.
Mar 04 09:12:02 01SVLBKP01 netbox-pre-start[2303]:   wireless.wirelesslink... No objects found.
Mar 04 09:12:02 01SVLBKP01 netbox-pre-start[2303]: Completed.
Mar 04 09:12:19 01SVLBKP01 systemd[1]: netbox.service: start-pre operation timed out. Terminating.
Mar 04 09:12:19 01SVLBKP01 systemd[1]: netbox.service: Control process exited, code=killed, status=15/TERM
░░ Subject: Unit process exited
░░ Defined-By: systemd
░░ Support: https://lists.freedesktop.org/mailman/listinfo/systemd-devel
░░
░░ An ExecStartPre= process belonging to unit netbox.service has exited.
░░
░░ The process' exit code is 'killed' and its exit status is 15.
Mar 04 09:12:19 01SVLBKP01 systemd[1]: netbox.service: Failed with result 'timeout'.
░░ Subject: Unit failed
░░ Defined-By: systemd
░░ Support: https://lists.freedesktop.org/mailman/listinfo/systemd-devel
░░
░░ The unit netbox.service has entered the 'failed' state with result 'timeout'.
Mar 04 09:12:19 01SVLBKP01 systemd[1]: Failed to start NetBox WSGI Service.
░░ Subject: A start job for unit netbox.service has failed
░░ Defined-By: systemd
░░ Support: https://lists.freedesktop.org/mailman/listinfo/systemd-devel
░░
░░ A start job for unit netbox.service has finished with a failure.
░░
░░ The job identifier is 4253 and the job result is failed.
Mar 04 09:12:19 01SVLBKP01 systemd[1]: netbox.service: Consumed 25.526s CPU time, received 22.1K IP traffic, sent 10.3K IP traffic.
░░ Subject: Resources consumed by unit runtime
░░ Defined-By: systemd
░░ Support: https://lists.freedesktop.org/mailman/listinfo/systemd-devel
░░
░░ The unit netbox.service completed and consumed the indicated resources.

Netbox configuration (don’t mind the commented parts. I tried a lot of things already.)

{
    services.netbox = {
        enable = true;
        secretKeyFile = "/var/lib/netbox/netboxkey";
        #listenAddress = "[::1]";
        dataDir = "/var/lib/netbox/";
#        settings = {
#            ALLOWED_HOSTS = [
#                "10.200.200.6"
#                "${config.networking.fqdn}"
#            ]
        };

    services.nginx = {
        enable = true;
        user = "netbox";
        recommendedTlsSettings = true;
        clientMaxBodySize = "25m";
            virtualHosts."${config.networking.fqdn}" = {
            #listenAddresses = [
                #"10.200.200.6"
                #];
            locations = {
                "/" = {
                proxyPass = "https://[::1]:8001/";
                #proxyPass = "http://${config.services.netbox.listenAddress}:${config.services.netbox.port}";
                };
                "/static/" = { alias = "${config.services.netbox.dataDir}/static/"; };
            };
            serverName = "${config.networking.fqdn}";
        #     forceSSL = true;
        #     enableACME = true;
        #     };
        };
    };
}

I would really appreciate any feedback pointing me in the right direction. I found that there’s not much documentation regarding Netbox on NixOS, so I assume that I’m just missing something pretty simple.

So I fixed the issue by doing two things:

  1. Changing the ownership of the Netbox-Key from netbox:netbox to root:netbox.
  2. Nginx-Proxy was pointing to "https://[::1]:8001/ while Netbox was listening to "http://[::1]:8001/.

Stupid mistakes on my side :smiley: