Skip to content

Commit

Permalink
Add systemd path-activation file for starting Saraswati after USB devs
Browse files Browse the repository at this point in the history
  • Loading branch information
amotl committed Jul 20, 2021
1 parent f2daf75 commit 357b148
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 5 deletions.
2 changes: 2 additions & 0 deletions CHANGES.rst
Expand Up @@ -7,6 +7,8 @@ in progress
===========

- Don't automatically start tailing the log file after "saraswati setup"
- Add systemd path-activation file in order to start the Saraswati service only
after all USB sound devices have been registered by watching ``/dev/bus/usb``.


2021-06-23 0.5.0
Expand Down
11 changes: 7 additions & 4 deletions saraswati/setup/systemd/__init__.py
Expand Up @@ -37,17 +37,20 @@ def run():
)
os.system(f"cp {defaultfile} /etc/default/saraswati")

# Copy systemd unit file. Always.
# Copy systemd unit and path-activation files. Always.
unitfile = pkg_resources.resource_filename(
"saraswati.setup.systemd", "saraswati.service"
)
os.system(f"cp {unitfile} /usr/lib/systemd/system/")
pathfile = pkg_resources.resource_filename(
"saraswati.setup.systemd", "saraswati.path"
)
os.system(f"cp {unitfile} {pathfile} /usr/lib/systemd/system/")

os.system(
"systemctl daemon-reload && systemctl enable saraswati && systemctl restart saraswati"
"systemctl daemon-reload && systemctl enable saraswati"
)
print()
print("Saraswati service started successfully")
print("Saraswati unit enabled successfully. The service will start when /dev/bus/usb is not empty.")
print()

# print("Start watching logfile using 'journalctl --unit=saraswati --follow'")
Expand Down
9 changes: 9 additions & 0 deletions saraswati/setup/systemd/saraswati.path
@@ -0,0 +1,9 @@
# https://superuser.com/questions/1322777/in-systemd-service-file-how-do-i-say-after-usb-is-ready
# https://www.freedesktop.org/software/systemd/man/systemd.path.html

[Unit]
Description=Saraswati multi-channel audio recording system
Documentation=https://github.com/hiveeyes/saraswati

[Path]
DirectoryNotEmpty=/dev/bus/usb
1 change: 0 additions & 1 deletion saraswati/setup/systemd/saraswati.service
@@ -1,7 +1,6 @@
[Unit]
Description=Saraswati multi-channel audio recording system
Documentation=https://github.com/hiveeyes/saraswati
After=network.target

[Service]
User=saraswati
Expand Down

0 comments on commit 357b148

Please sign in to comment.