@@ -10975,31 +10975,11 @@ def bind_deploy_paths() -> InjectorBindings:
1097510975########################################
1097610976# ../deploy/systemd.py
1097710977"""
10978- ~/.config/systemd/user/
10979-
10980- verify - systemd-analyze
10981-
10982- sudo loginctl enable-linger "$USER"
10983-
10984- cat ~/.config/systemd/user/sleep-infinity.service
10985- [Unit]
10986- Description=User-specific service to run 'sleep infinity'
10987- After=default.target
10988-
10989- [Service]
10990- ExecStart=/bin/sleep infinity
10991- Restart=always
10992- RestartSec=5
10993-
10994- [Install]
10995- WantedBy=default.target
10996-
10997- systemctl --user daemon-reload
10998-
10999- systemctl --user enable sleep-infinity.service
11000- systemctl --user start sleep-infinity.service
11001-
11002- systemctl --user status sleep-infinity.service
10978+ TODO:
10979+ - verify - systemd-analyze
10980+ - sudo loginctl enable-linger "$USER"
10981+ - idemp kill services that shouldn't be running, start ones that should
10982+ - ideally only those defined by links to deploy home
1100310983"""
1100410984
1100510985
@@ -11038,13 +11018,17 @@ async def sync_systemd(
1103811018 if not spec :
1103911019 return
1104011020
11021+ #
11022+
1104111023 if not (ud := spec .unit_dir ):
1104211024 return
1104311025
1104411026 ud = abs_real_path (os .path .expanduser (ud ))
1104511027
1104611028 os .makedirs (ud , exist_ok = True )
1104711029
11030+ #
11031+
1104811032 uld = {
1104911033 n : p
1105011034 for n , p in self ._scan_link_dir (ud ).items ()
@@ -11056,8 +11040,11 @@ async def sync_systemd(
1105611040 else :
1105711041 cld = {}
1105811042
11059- for n in sorted (set (uld ) | set (cld )):
11060- ul = uld .get (n ) # noqa
11043+ #
11044+
11045+ ns = sorted (set (uld ) | set (cld ))
11046+
11047+ for n in ns :
1106111048 cl = cld .get (n )
1106211049 if cl is None :
1106311050 os .unlink (os .path .join (ud , n ))
@@ -11074,6 +11061,38 @@ async def sync_systemd(
1107411061 dst_swap .tmp_path ,
1107511062 )
1107611063
11064+ #
11065+
11066+ if sys .platform == 'linux' :
11067+ async def reload () -> None :
11068+ await asyncio_subprocesses .check_call ('systemctl' , '--user' , 'daemon-reload' )
11069+
11070+ await reload ()
11071+
11072+ num_deleted = 0
11073+ for n in ns :
11074+ if n .endswith ('.service' ):
11075+ cl = cld .get (n )
11076+ ul = uld .get (n )
11077+ if cl is not None :
11078+ if ul is None :
11079+ cs = ['enable' , 'start' ]
11080+ else :
11081+ cs = ['restart' ]
11082+ else : # noqa
11083+ if ul is not None :
11084+ cs = []
11085+ # cs = ['stop']
11086+ # num_deleted += 1
11087+ else :
11088+ cs = []
11089+
11090+ for c in cs :
11091+ await asyncio_subprocesses .check_call ('systemctl' , '--user' , c , n )
11092+
11093+ if num_deleted :
11094+ await reload ()
11095+
1107711096
1107811097########################################
1107911098# ../remote/inject.py
@@ -11455,12 +11474,15 @@ async def setup_venv(
1145511474
1145611475 if os .path .isfile (reqs_txt ):
1145711476 if spec .use_uv :
11458- await asyncio_subprocesses .check_call (venv_exe , '-m' , 'pip' , 'install' , 'uv' )
11459- pip_cmd = ['-m' , 'uv' , 'pip' ]
11477+ if shutil .which ('uv' ) is not None :
11478+ pip_cmd = ['uv' , 'pip' ]
11479+ else :
11480+ await asyncio_subprocesses .check_call (venv_exe , '-m' , 'pip' , 'install' , 'uv' )
11481+ pip_cmd = [venv_exe , '-m' , 'uv' , 'pip' ]
1146011482 else :
11461- pip_cmd = ['-m' , 'pip' ]
11483+ pip_cmd = [venv_exe , '-m' , 'pip' ]
1146211484
11463- await asyncio_subprocesses .check_call (venv_exe , * pip_cmd ,'install' , '-r' , reqs_txt )
11485+ await asyncio_subprocesses .check_call (* pip_cmd , 'install' , '-r' , reqs_txt , cwd = venv_dir )
1146411486
1146511487
1146611488########################################
0 commit comments