|
31 | 31 | # remove binfmt.d(5) configuration if it exists
|
32 | 32 | [ ! -f "$binfmtd_conf" ] || rm "$binfmtd_conf"
|
33 | 33 | fi
|
| 34 | + |
| 35 | +if [ -x /mnt/lima-rosetta/rosettad ]; then |
| 36 | + CACHE_DIRECTORY=/var/cache/rosettad |
| 37 | + DEFAULT_SOCKET=${CACHE_DIRECTORY}/uds/rosetta.sock |
| 38 | + EXPECTED_SOCKET=/run/rosettad/rosetta.sock |
| 39 | + |
| 40 | + # Create rosettad service |
| 41 | + if [ -f /sbin/openrc-run ]; then |
| 42 | + cat >/etc/init.d/rosettad <<EOF |
| 43 | +#!/sbin/openrc-run |
| 44 | +name="rosettad" |
| 45 | +description="Rosetta AOT Caching Daemon" |
| 46 | +required_dirs=/mnt/lima-rosetta |
| 47 | +required_files=/mnt/lima-rosetta/rosettad |
| 48 | +command=/mnt/lima-rosetta/rosettad |
| 49 | +command_args="daemon ${CACHE_DIRECTORY}" |
| 50 | +command_background=true |
| 51 | +pidfile="/run/rosettad.pid" |
| 52 | +start_pre() { |
| 53 | + # To detect creation of the socket by rosettad, remove the old socket before starting |
| 54 | + test ! -e "${DEFAULT_SOCKET}" || rm -f "${DEFAULT_SOCKET}" |
| 55 | +} |
| 56 | +start_post() { |
| 57 | + # Set the socket permission to world-writable |
| 58 | + while ! chmod -f go+w "${DEFAULT_SOCKET}"; do sleep 1; done |
| 59 | + # Create the symlink as expected by the configuration to enable Rosetta AOT caching |
| 60 | + mkdir -p "$(dirname "${EXPECTED_SOCKET}")" |
| 61 | + ln -sf "${DEFAULT_SOCKET}" "${EXPECTED_SOCKET}" |
| 62 | +} |
| 63 | +EOF |
| 64 | + chmod 755 /etc/init.d/rosettad |
| 65 | + rc-update add rosettad default |
| 66 | + rc-service rosettad start |
| 67 | + else |
| 68 | + cat >/etc/systemd/system/rosettad.service <<EOF |
| 69 | +[Unit] |
| 70 | +Description=Rosetta AOT Caching Daemon |
| 71 | +RequiresMountsFor=/mnt/lima-rosetta |
| 72 | +[Service] |
| 73 | +RuntimeDirectory=rosettad |
| 74 | +CacheDirectory=rosettad |
| 75 | +# To detect creation of the socket by rosettad, remove the old socket |
| 76 | +ExecStartPre=sh -c "test ! -e \"${DEFAULT_SOCKET}\" || rm -f \"${DEFAULT_SOCKET}\"" |
| 77 | +ExecStart=/mnt/lima-rosetta/rosettad daemon "${CACHE_DIRECTORY}" |
| 78 | +# Set the socket permission to world-writable and create the symlink as expected by the configuration to enable Rosetta AOT caching. |
| 79 | +ExecStartPost=sh -c "while ! chmod -f go+w \"${DEFAULT_SOCKET}\"; do sleep 1; done; ln -sf \"${DEFAULT_SOCKET}\" \"${EXPECTED_SOCKET}\"" |
| 80 | +OOMPolicy=continue |
| 81 | +OOMScoreAdjust=-500 |
| 82 | +[Install] |
| 83 | +WantedBy=default.target |
| 84 | +EOF |
| 85 | + systemctl is-enabled rosettad || systemctl enable --now rosettad |
| 86 | + fi |
| 87 | + |
| 88 | + # Create CDI configuration for Rosetta |
| 89 | + mkdir -p /etc/cdi /var/run/cdi /etc/buildkit/cdi |
| 90 | + cat >/etc/cdi/rosetta.yaml <<EOF |
| 91 | +cdiVersion: "0.6.0" |
| 92 | +kind: "lima-vm.io/rosetta" |
| 93 | +devices: |
| 94 | +- name: cached |
| 95 | + containerEdits: |
| 96 | + mounts: |
| 97 | + - hostPath: /var/cache/rosettad/uds/rosetta.sock |
| 98 | + containerPath: /run/rosettad/rosetta.sock |
| 99 | + options: [bind] |
| 100 | +annotations: |
| 101 | + org.mobyproject.buildkit.device.autoallow: true |
| 102 | +EOF |
| 103 | + # nerdctl requires user-specific CDI configuration directories |
| 104 | + mkdir -p "${LIMA_CIDATA_HOME}/.config/cdi" |
| 105 | + ln -sf /etc/cdi/rosetta.yaml "${LIMA_CIDATA_HOME}/.config/cdi/" |
| 106 | + chown -R "${LIMA_CIDATA_USER}" "${LIMA_CIDATA_HOME}/.config" |
| 107 | +else |
| 108 | + # Remove CDI configuration for Rosetta AOT Caching |
| 109 | + [ ! -f /etc/cdi/rosetta.yaml ] || rm /etc/cdi/rosetta.yaml |
| 110 | + [ ! -d "${LIMA_CIDATA_HOME}/.config/cdi/rosetta.yaml" ] || rm "${LIMA_CIDATA_HOME}/.config/cdi/rosetta.yaml" |
| 111 | +fi |
0 commit comments