Skip to content

Record a sky camera around the clock, keep the footage on your own disk, and find what flew past.

fix(linux): write WorkingDirectory= unquoted so systemd accepts the unit (#10)

viwe-monai0d73edce0242
diff --git a/processor/install-model-sync.sh b/processor/install-model-sync.sh
index 929cebe..d27fd81 100644
--- a/processor/install-model-sync.sh
+++ b/processor/install-model-sync.sh
@@ -42,6 +42,8 @@ elif sys.platform.startswith('linux'):
def quote(value, expand=True): # systemd unit quoting; ExecStart= also expands $
value = value.replace('\\', '\\\\').replace('"', '\\"').replace('%', '%%')
return '"' + (value.replace('$', '$$') if expand else value) + '"'
+ def unit_path(value): # systemd never strips quotes from WorkingDirectory=, so write it raw
+ return value.replace('%', '%%')
folder = Path.home() / '.config/systemd/user'
folder.mkdir(parents=True, exist_ok=True)
name = 'skyvision-models-' + device
@@ -49,7 +51,7 @@ elif sys.platform.startswith('linux'):
files = {
folder / (name + '.service'): '\n'.join([
'[Unit]', f'Description=SkyVision model sync ({device})', '',
- '[Service]', 'Type=oneshot', 'WorkingDirectory=' + quote(source, False),
+ '[Service]', 'Type=oneshot', 'WorkingDirectory=' + unit_path(source),
'Environment=PYTHONUNBUFFERED=1', 'Environment=PYTHONDONTWRITEBYTECODE=1',
'ExecStart=' + ' '.join(quote(a) for a in arguments),
'Nice=10', 'IOSchedulingClass=idle', 'StandardOutput=null', 'StandardError=null', '']).encode(),
diff --git a/processor/install-workshop.sh b/processor/install-workshop.sh
index c951484..4c4d95d 100755
--- a/processor/install-workshop.sh
+++ b/processor/install-workshop.sh
@@ -44,11 +44,13 @@ elif sys.platform.startswith('linux'):
def quote(value, expand=True): # systemd unit quoting; ExecStart= also expands $
value = value.replace('\\', '\\\\').replace('"', '\\"').replace('%', '%%')
return '"' + (value.replace('$', '$$') if expand else value) + '"'
+ def unit_path(value): # systemd never strips quotes from WorkingDirectory=, so write it raw
+ return value.replace('%', '%%')
folder = Path.home() / '.config/systemd/user'; folder.mkdir(parents=True, exist_ok=True)
path = folder / 'skyvision-workshop.service'
content = '\n'.join([
'[Unit]', 'Description=SkyVision Workshop runner', 'After=network-online.target', 'StartLimitIntervalSec=0', '',
- '[Service]', 'WorkingDirectory=' + quote(source, False),
+ '[Service]', 'WorkingDirectory=' + unit_path(source),
*('Environment=' + quote(f'{k}={v}', False) for k, v in environment.items()),
'ExecStart=' + ' '.join(quote(a) for a in arguments),
'Restart=always', 'RestartSec=30', 'Nice=10', 'IOSchedulingClass=best-effort', 'IOSchedulingPriority=7',
diff --git a/processor/tests/test_installers.py b/processor/tests/test_installers.py
index aac749b..2e4787a 100644
--- a/processor/tests/test_installers.py
+++ b/processor/tests/test_installers.py
@@ -58,7 +58,8 @@ class LinuxUnits(unittest.TestCase):
text = unit.read_text()
self.assertIn('ExecStart="/opt/my env/bin/python" "-m" "skyvision_processor" "workshop-run" "--base-url" '
f'"https://api.example.com" "--key-file" "{self.key}" "--runtime" "workshop-{"a" * 32}" "--watch"', text)
- self.assertIn('WorkingDirectory="/src 100%%"', text)
+ self.assertIn('WorkingDirectory=/src 100%%\n', text)
+ self.assertNotIn('WorkingDirectory="', text)
self.assertIn('Environment="PYTHONPATH=/src 100%%:/deps"', text)
for line in ('Restart=always', 'Nice=10', 'WantedBy=default.target', 'Environment="PYTHONUNBUFFERED=1"'):
self.assertIn(line + '\n', text)
@@ -80,6 +81,8 @@ class LinuxUnits(unittest.TestCase):
self.assertIn('OnUnitActiveSec=60\n', timer.read_text())
service = timer.with_suffix('.service').read_text()
self.assertIn('Type=oneshot\n', service)
+ self.assertIn('WorkingDirectory=/src\n', service)
+ self.assertNotIn('WorkingDirectory="', service)
self.assertIn('"sync-models" "--base-url" "https://api.example.com" "--key-file"', service)
self.assertNotEqual(0, install('install-model-sync.sh', '/py', 'Bad Device', str(self.key), 'https://x', '/m', '/s',
home=self.home).returncode)