From 5a9ea9d779275822950811bdfc12827938cc0210 Mon Sep 17 00:00:00 2001 From: DIL5 Date: Wed, 14 Oct 2026 15:22:59 +0200 Subject: [PATCH] reorganize fixup directories - to_system_apu instead of apu_system - to_config_desktop instead of desktop + remove the need of waitboot, add ExecStartPre or frappy and boxweb --- cfg/linse-dil5.cfg | 2 +- install.py | 60 +++++++++---------- linse-dil5apu.cfg | 21 ------- .../boxweb-browser.service | 0 {desktop => to_config_desktop}/labwc.service | 2 - to_home/.config/systemd/user/waitboot.service | 10 ---- {apu_system => to_system_apu}/etc/chrony.conf | 0 todo/boxweb-browser.service | 12 ---- todo/labwc.service | 11 ---- 9 files changed, 30 insertions(+), 88 deletions(-) delete mode 100644 linse-dil5apu.cfg rename {desktop => to_config_desktop}/boxweb-browser.service (100%) rename {desktop => to_config_desktop}/labwc.service (83%) delete mode 100644 to_home/.config/systemd/user/waitboot.service rename {apu_system => to_system_apu}/etc/chrony.conf (100%) delete mode 100644 todo/boxweb-browser.service delete mode 100644 todo/labwc.service diff --git a/cfg/linse-dil5.cfg b/cfg/linse-dil5.cfg index 45271c7..203658c 100644 --- a/cfg/linse-dil5.cfg +++ b/cfg/linse-dil5.cfg @@ -17,5 +17,5 @@ cfg=dil5 [BOXWEB] port=8050 -wsport=8010 +wsport=8051 page=dil5 diff --git a/install.py b/install.py index 8807386..06fc101 100755 --- a/install.py +++ b/install.py @@ -136,10 +136,10 @@ WantedBy = multi-user.target FRAPPY_SERVICE = """[Unit] Description = Running frappy server -After=network-online.target -Wants=network-online.target [Service] +# wait for network is online +ExecStartPre=/bin/sh -c 'until systemctl is-active --quiet network-online.target; do sleep 1; done' Type=simple Environment=PYTHONPATH=/home/l_samenv/.local/lib/python3.11/site-packages/ ExecStart = /home/l_samenv/boxtools/start_frappy @@ -162,11 +162,13 @@ WantedBy = multi-user.target BOXWEB_SERVICE = """[Unit] Description = Web service for local GUI on a box -After = waitboot.target [Service] WorkingDirectory = /home/l_samenv/boxweb -ExecStart = /usr/bin/python flaskserver.py {page}.{port}.{wsport} +TimeoutStartSec = 60 +# wait for frappy server serving websocket {wsport} is running +ExecStartPre = /bin/sh -c 'until ss -H -ltn "sport = :{wsport}" | grep -q .; do sleep 1; done' +ExecStart = /usr/bin/python3 flaskserver.py {page}.{port}.{wsport} [Install] WantedBy = default.target @@ -175,11 +177,14 @@ WantedBy = default.target pip_requirements = {} box = BoxInfo() +box.fixup_dirs = [ # (src, dst, as_root) + (TOOLS / 'to_system', Path('/'), True), + (TOOLS / f'to_system_{box.typ}', Path('/'), True), + (TOOLS / 'to_home', Path.home(), False), +] box.hostname_changed = False dhcp_server_cfg = [] -to_system = [TOOLS / 'to_system'] - def do_cmd(*command, sudo=True): unix_cmd(*command, execute=doit, sudo=sudo) @@ -269,14 +274,16 @@ def boxweb(port=8080, wsport=8051, page=None): main_ports.add(wsport) if port == 8080: main_ports.add(80) + config = box.read_config() servicecfg = BOXWEB_SERVICE.format(port=port, wsport=wsport, page=page) - for file, dest in (('labwc.service', '/etc/systemd/system'), - ('boxweb-browser.service', '/home/l_samenv/.config/systemd/user')): - src = TOOLS / 'desktop' / file - dst = Path(dest) / file - if not page: - src = None # -> remove - do_copy(src, dst) + box.fixup_dirs.append((TOOLS / 'to_config_desktop', Path('~/.config/systemd/user').expanduser(), False)) + #for file, dest in (('labwc.service', '/home/l_samenv/.config/systemd/user'), + # ('boxweb-browser.service', '/home/l_samenv/.config/systemd/user')): + # src = TOOLS / 'desktop' / file + # dst = Path(dest) / file + # if not page: + # src = None # -> remove + # do_copy(src, dst) return port <= 1024, servicecfg @@ -392,6 +399,8 @@ def write_when_new(filename, content, as_root=False, ignore_reduction=False): print('\n'.join(old[-bottom_lines:-1])) print("===") print('.' * 80) + else: + print('write', filename) return content @@ -498,17 +507,12 @@ def walk_dir(action, srcpath, dstroot, files): def walk(action): - action.as_root = True - for rootpath in to_system: - if not rootpath.exists(): - continue - os.chdir(rootpath) - for srcpath, _, files in os.walk('.'): - walk_dir(action, srcpath, Path('/'), files) - os.chdir(TOOLS / 'to_home') - action.as_root = False - for srcpath, _, files in os.walk('.'): - walk_dir(action, srcpath, Path.home(), files) + for src, dst, as_root in box.fixup_dirs: + if src.exists(): + action.as_root = as_root + os.chdir(src) + for srcpath, _, files in os.walk('.'): + walk_dir(action, srcpath, dst, files) class Walker: @@ -656,8 +660,6 @@ def handle_config(): config = box.read_config() box.hostname = newhostname update_host_key(newhostname) - if len(to_system) == 1: - to_system.append(TOOLS / f'to_{box.typ}') if cfgfile is None: return False to_start = {} # dict of , @@ -755,10 +757,7 @@ def handle_config(): if pip_requirements: pip() for as_root in reload_systemd: - if as_root: - do_cmd('systemctl daemon-reload', sudo=True) - else: - do_cmd('systemctl --user daemon-reload', sudo=False) + do_cmd('systemctl daemon-reload', sudo=as_root) # '--user' will be inserted inside for service, (action, _) in to_start.items(): show.dirty = True if action == 'if_restart': @@ -792,7 +791,6 @@ def handle_config(): doit = False print(' ') show = Show() -#walk(show) result = handle_config() walk(show) diff --git a/linse-dil5apu.cfg b/linse-dil5apu.cfg deleted file mode 100644 index d7ddfd7..0000000 --- a/linse-dil5apu.cfg +++ /dev/null @@ -1,21 +0,0 @@ -[BOX] -type=bare-apu -MAC=00:0d:b9:59:1f:ac - -[NETWORK] -; please refer to README.md for help -eth0=dhcp -eth1=192.168.2.32 -eth2=192.168.3.1 -eth3=192.168.127.254 - -[ROUTER] -; please refer to README.md for help -3000=/dev/ttyACM0 -5900=192.168.2.32 -33576=192.168.2.32 -8080=192.168.127.254:80 -3001=192.168.127.254:3001 -3002=192.168.127.254:3002 -3003=192.168.127.254:3003 -3004=192.168.127.254:3004 diff --git a/desktop/boxweb-browser.service b/to_config_desktop/boxweb-browser.service similarity index 100% rename from desktop/boxweb-browser.service rename to to_config_desktop/boxweb-browser.service diff --git a/desktop/labwc.service b/to_config_desktop/labwc.service similarity index 83% rename from desktop/labwc.service rename to to_config_desktop/labwc.service index 448cdd9..0e6ef7e 100644 --- a/desktop/labwc.service +++ b/to_config_desktop/labwc.service @@ -2,8 +2,6 @@ Description=LabWC Wayland compositor [Service] -User=l_samenv -Type=simple ExecStart=/usr/bin/labwc Restart=on-failure diff --git a/to_home/.config/systemd/user/waitboot.service b/to_home/.config/systemd/user/waitboot.service deleted file mode 100644 index c1df2fb..0000000 --- a/to_home/.config/systemd/user/waitboot.service +++ /dev/null @@ -1,10 +0,0 @@ -[Unit] -Description = wait a little after startup -After = network.target - -[Service] -Type=oneshot -ExecStart = /usr/bin/sleep 10 - -[Install] -WantedBy = default.target diff --git a/apu_system/etc/chrony.conf b/to_system_apu/etc/chrony.conf similarity index 100% rename from apu_system/etc/chrony.conf rename to to_system_apu/etc/chrony.conf diff --git a/todo/boxweb-browser.service b/todo/boxweb-browser.service deleted file mode 100644 index 0b16624..0000000 --- a/todo/boxweb-browser.service +++ /dev/null @@ -1,12 +0,0 @@ -[Unit] -Description = Running Web Browser for boxweb -Requires=labwc.service -Requires=boxweb.service - -[Service] -Type=simple -ExecStart = /usr/bin/python /home/l_samenv/boxweb/start_browser.py - -[Install] -WantedBy = default.target - diff --git a/todo/labwc.service b/todo/labwc.service deleted file mode 100644 index f8062d6..0000000 --- a/todo/labwc.service +++ /dev/null @@ -1,11 +0,0 @@ -[Unit] -Description=LabWC Wayland compositor -After=graphical.target - -[Service] -Type=simple -ExecStart=/usr/bin/labwc -Restart=on-failure - -[Install] -WantedBy=default.target