Skip to content

A rootless Android app that boots Alpine Linux: run containers (Podman/Docker/LXC) and GUI desktop apps.

1.8 KB
Raw Blame
#!/sbin/openrc-run
description="Podroid AVF Downloads share (9p over vsock, AVF only)"
pidfile="/run/podroid-downloads.pid"

depend() {
    need podroid-bootstrap
    after podroid-network podroid-vsock
    before podroid-ready
}

start() {
    # AVF-only: QEMU's kernel has no AF_VSOCK and already gets its Downloads
    # share via virtio-9p in podroid-bootstrap. Skip cleanly via
    # mark_service_inactive, same idiom podroid-vsock uses.
    if ! grep -q 'podroid\.backend=avf' /proc/cmdline 2>/dev/null; then
        einfo "Not an AVF boot - skipping podroid-downloads"
        mark_service_inactive
        return 0
    fi
    mkdir -p /mnt/downloads 2>/dev/null
    ebegin "Starting Downloads 9p rendezvous"
    start-stop-daemon --start --background \
        --make-pidfile --pidfile "$pidfile" \
        --stdout /var/log/podroid-downloads.log \
        --stderr /var/log/podroid-downloads.log \
        --exec /usr/local/bin/podroid-vsock-agent -- downloads-9p
    eend $?

    # One-time cleanup of the stray container-count file an older Podroid
    # version wrote into the user's real Downloads dir (the guest host bridge's
    # STATS push replaced it). Detached because the 9p mount above completes
    # asynchronously once Android accepts the vsock rendezvous; rm -f is
    # idempotent so giving up after the wait just leaves it for next boot.
    ( _i=0
      while [ "$_i" -lt 30 ] && ! mountpoint -q /mnt/downloads 2>/dev/null; do
          sleep 1
          _i=$((_i + 1))
      done
      rm -f /mnt/downloads/Podroid/container-count 2>/dev/null
    ) &
}

stop() {
    if [ -f "$pidfile" ]; then
        ebegin "Stopping Downloads 9p rendezvous"
        start-stop-daemon --stop --pidfile "$pidfile"
        rm -f "$pidfile"
        eend $?
    fi
    umount /mnt/downloads 2>/dev/null || true
    return 0
}