Skip to content

Startup failures #341

@dpw13

Description

@dpw13

I've noticed that restarting the lightNVR service using systemctl restart lightnvr often results in the service not fully coming up. The last few lines of log that appear in this case are:

[2026-03-27 14:06:26] [INFO] Logging to file: /var/log/lightnvr.log
[2026-03-27 14:06:26] [ERROR] Log level set to 2 (INFO)
[2026-03-27 14:06:26] [INFO] Shutdown coordinator initialized
[2026-03-27 14:06:26] [INFO] Shutdown coordinator initialized
[2026-03-27 14:06:26] [INFO] Signal handlers initialized with improved handling
[2026-03-27 14:06:26] [INFO] Starting in daemon mode
[2026-03-27 14:06:26] [INFO] Starting daemon mode with PID file: /var/run/lightnvr.pid
[2026-03-27 14:06:26] [INFO] Current working directory: /
[2026-03-27 14:06:26] [INFO] Parent process exiting, child PID: 445016
[2026-03-27 14:06:26] [INFO] Child process starting daemon initialization, PID: 445016
[2026-03-27 14:06:26] [INFO] Created new session with SID: 445016
[2026-03-27 14:06:26] [INFO] Keeping current working directory for SQLite compatibility: /
[2026-03-27 14:06:26] [INFO] Keeping all file descriptors open for web server compatibility
[2026-03-27 14:06:26] [INFO] Signal handlers configured
[2026-03-27 14:06:26] [INFO] Writing PID file...
[2026-03-27 14:06:26] [INFO] Wrote PID 445016 to file /var/run/lightnvr.pid
[2026-03-27 14:06:26] [INFO] Daemon started successfully with PID 445016
[2026-03-27 14:06:26] [INFO] [StorageManager] Initial cache refresh successful
[2026-03-27 14:06:27] [INFO] Stream state manager initialized (16 slots)
[2026-03-27 14:06:27] [INFO] Stream state adapter initialized

I usually have to restart between 3 and 6 times before startup properly continues:

...
[2026-03-27 14:07:39] [INFO] Writing PID file...
[2026-03-27 14:07:39] [INFO] Wrote PID 445059 to file /var/run/lightnvr.pid
[2026-03-27 14:07:39] [INFO] Daemon started successfully with PID 445059
[2026-03-27 14:07:39] [INFO] Stream state manager initialized (16 slots)
[2026-03-27 14:07:39] [INFO] Stream state adapter initialized
[2026-03-27 14:07:39] [INFO] Created stream state for 'cam_a' in slot 0 with initial reference count 1
[2026-03-27 14:07:39] [INFO] Created stream state for 'cam_a' during initialization
[2026-03-27 14:07:39] [WARN] go2rtc_stream_is_ready: not initialized
[2026-03-27 14:07:39] [INFO] Created stream state for 'cam_b' in slot 1 with initial reference count 1
[2026-03-27 14:07:39] [INFO] Created stream state for 'cam_b' during initialization
[2026-03-27 14:07:39] [WARN] go2rtc_stream_is_ready: not initialized
[2026-03-27 14:07:39] [INFO] Stream manager initialized
...

I originally thought this felt like a race condition, but I suspect that it may due to an uninitialized global, maybe a mutex? I realize that pthread_mutex_t is an opaque type, but at least on Debian Trixie (gcc 14.2.0) initializing with the generic zero initializer {0} does properly compile. I haven't verified whether that fixes the issue or not. If the issue is an uninitialized global, it should probably get properly initialized rather than just zeroed. I forgot PTHREAD_MUTEX_INITIALIZER exists. That should be used for all mutex globals. I'll put up a PR shortly since that ought to be done regardless.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions