Skip to content

Commit ddcf118

Browse files
committed
replace python3-sdnotify with vocto.sd_notify, use in voctogui
This also adds some status information to systemd, allowing users to see what voctocore is doing without needing to dig through the logs.
1 parent a70a36b commit ddcf118

File tree

9 files changed

+65
-22
lines changed

9 files changed

+65
-22
lines changed

debian/control

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ Depends: gstreamer1.0-plugins-bad,
2424
python3-gi,
2525
gir1.2-gstreamer-1.0,
2626
gir1.2-gst-plugins-base-1.0,
27-
python3-sdnotify,
2827
gstreamer1.0-gl,
2928
gstreamer1.0-pulseaudio
3029
Suggests: gstreamer1.0-vaapi,
@@ -37,4 +36,4 @@ Suggests: gstreamer1.0-vaapi,
3736
python3-flask,
3837
python3-scipy,
3938
Description: Voc2Mix ISDN version
40-
Full-HD Software Live-Video-Mixer in python
39+
Full-HD Software Live-Video-Mixer in python

pyproject.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ dependencies = [
88
"numpy<2.0",
99
"scipy>=1.15.2",
1010
"scipy-stubs>=1.15.2.1",
11-
"sdnotify>=0.3.2",
1211
]
1312

1413
[dependency-groups]

uv.lock

Lines changed: 0 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vocto/sd_notify.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
from os import environ
2+
import socket
3+
from logging import getLogger
4+
5+
class SystemdNotify:
6+
def __init__(self):
7+
self.log = getLogger('SystemdNotify')
8+
9+
addr = environ.get('NOTIFY_SOCKET')
10+
self.log.debug(f'{addr=}')
11+
if not addr:
12+
self.log.info('SD_NOTIFY not available')
13+
self.socket = None
14+
return
15+
16+
self.log.info('SD_NOTIFY support enabled')
17+
self.socket = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM)
18+
if addr[0] == '@':
19+
addr = '\0' + addr[1:]
20+
self.socket.connect(addr)
21+
22+
def _send(self, msg):
23+
if not self.socket:
24+
# It's fine if we don't have a socket, that just means this
25+
# software was started without systemds 'Type=notify'
26+
self.log.debug(f'_send({msg!r}) called, but socket is not available')
27+
return
28+
29+
self.log.info(msg)
30+
self.socket.sendall((msg.strip() + '\n').encode())
31+
32+
def ready(self):
33+
self._send('READY=1')
34+
35+
def reloading(self):
36+
self._send('RELOADING=1')
37+
38+
def stopping(self):
39+
self._send('STOPPING=1')
40+
41+
def status(self, msg):
42+
self._send(f'STATUS={msg}')
43+
44+
45+
sd_notify = SystemdNotify()

voctocore/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ git checkout voctomix2
117117
### 1.4.2. Requirements
118118

119119
````bash
120-
sudo apt install gstreamer1.0-plugins-bad gstreamer1.0-plugins-base gstreamer1.0-plugins-good gstreamer1.0-plugins-ugly gstreamer1.0-tools libgstreamer1.0-0 gstreamer1.0-x python3 python3-gi gir1.2-gstreamer-1.0 gir1.2-gst-plugins-base-1.0 python3-sdnotify python3-scipy gstreamer1.0-gl gstreamer1.0-pulseaudio
120+
sudo apt install gstreamer1.0-plugins-bad gstreamer1.0-plugins-base gstreamer1.0-plugins-good gstreamer1.0-plugins-ugly gstreamer1.0-tools libgstreamer1.0-0 gstreamer1.0-x python3 python3-gi gir1.2-gstreamer-1.0 gir1.2-gst-plugins-base-1.0 python3-scipy gstreamer1.0-gl gstreamer1.0-pulseaudio
121121
````
122122

123123
### 1.4.3. For vaapi en/decoding

voctocore/__main__.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
#!/usr/bin/env python3
22
import gi
3-
import sdnotify
43
import signal
54
import logging
65
import sys
76

87
from vocto.debug import gst_log_messages
8+
from vocto.sd_notify import sd_notify
99

1010
# import GStreamer and GLib-Helper classes
1111
gi.require_version('Gst', '1.0')
@@ -53,7 +53,9 @@ def __init__(self):
5353
def run(self):
5454
self.log.info('Running. Waiting for connections....')
5555
try:
56+
sd_notify.ready()
5657
self.mainloop.run()
58+
sd_notify.stopping()
5759
except KeyboardInterrupt:
5860
self.log.info('Terminated via Ctrl-C')
5961

@@ -96,11 +98,6 @@ def main():
9698
logging.debug('initializing Voctocore')
9799
voctocore = Voctocore()
98100

99-
# Inform systemd that we are ready
100-
# for use with the notify service type
101-
n = sdnotify.SystemdNotifier()
102-
n.notify("READY=1")
103-
104101
logging.debug('running Voctocore')
105102
voctocore.run()
106103

voctocore/lib/controlserver.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from voctocore.lib.tcpmulticonnection import TCPMultiConnection
1010

1111
from vocto.port import Port
12+
from vocto.sd_notify import sd_notify
1213

1314

1415
class ControlServer(TCPMultiConnection):
@@ -30,6 +31,11 @@ def __init__(self, pipeline):
3031

3132
self.commands = ControlServerCommands(pipeline)
3233

34+
def _log_num_connections(self):
35+
# Overwrite method of TCPMultiConnection to add status information to sd_notify
36+
self.log.info(f'Now {self.num_connections()} Receiver(s) connected')
37+
sd_notify.status(f'{self.num_connections()} receiver(s) connected to ControlServer')
38+
3339
def on_accepted(self, conn, addr):
3440
'''Asynchronous connection listener.
3541
Starts a handler for each connection.'''

voctocore/lib/tcpmulticonnection.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ def port(self) -> str:
4646
def num_connections(self) -> int:
4747
return len(self.currentConnections)
4848

49+
def _log_num_connections(self):
50+
# lives in its own method so we can overwrite it in children
51+
self.log.info(f'Now {self.num_connections()} Receiver(s) connected')
52+
4953
def is_input(self) -> bool:
5054
return False
5155

@@ -57,8 +61,7 @@ def on_connect(self, sock: socket.socket, *args):
5761
addr[0], addr[1], conn.fileno())
5862

5963
self.currentConnections[conn] = Queue()
60-
self.log.info('Now %u Receiver(s) connected',
61-
len(self.currentConnections))
64+
self._log_num_connections()
6265

6366
self.on_accepted(conn, addr)
6467

@@ -68,8 +71,7 @@ def close_connection(self, conn: socket.socket):
6871
if conn in self.currentConnections:
6972
conn.close()
7073
del(self.currentConnections[conn])
71-
self.log.info('Now %u Receiver connected',
72-
len(self.currentConnections))
74+
self._log_num_connections()
7375

7476
@abstractmethod
7577
def on_accepted(self, conn: socket.socket, addr: tuple[str, int]):

voctogui/__main__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import os
1414

1515
from vocto.debug import gst_log_messages
16+
from vocto.sd_notify import sd_notify
1617

1718
# check min-version
1819
minGst = (1, 5)
@@ -87,7 +88,9 @@ def run(self) -> None:
8788

8889
try:
8990
self.log.info('Running.')
91+
sd_notify.ready()
9092
Gtk.main()
93+
sd_notify.stopping()
9194
self.log.info('Connection lost. Exiting.')
9295
except KeyboardInterrupt:
9396
self.log.info('Terminated via Ctrl-C')

0 commit comments

Comments
 (0)