Switch to transient service unit. Socket-triggering fails for now.

This commit is contained in:
Andreas B. Mundt 2023-09-13 19:32:25 +02:00
parent 8aca770c40
commit cb2ed82715
4 changed files with 38 additions and 22 deletions

View file

@ -96,7 +96,7 @@ create-clone() {
# and actually rename the vm (this also updates part of the storage path): # and actually rename the vm (this also updates part of the storage path):
sed -i "s/${VM_NAME}/${VM_NAME}-clone/" "${VM_XML}" sed -i "s/${VM_NAME}/${VM_NAME}-clone/" "${VM_XML}"
# set virtiofs-Socket # set virtiofs-Socket
sed -i "s:VIRTIOFSSOCKET:/run/virtiofs/${VM_NAME}-clone.sock:" "${VM_XML}" sed -i "s:VIRTIOFSSOCKET:/run/user/${UID}/virtiofs-${VM_NAME}.sock:" "${VM_XML}"
} }
QEMU='qemu:///session' QEMU='qemu:///session'

View file

@ -15,4 +15,36 @@ VM_NAME="$1"
chgrp 1010 "/lmn/media/${SUDO_USER}" chgrp 1010 "/lmn/media/${SUDO_USER}"
chmod 0775 "/lmn/media/${SUDO_USER}" chmod 0775 "/lmn/media/${SUDO_USER}"
systemctl start virtiofs@${VM_NAME}-clone:${SUDO_USER}.service socket="/run/user/$(id -u $SUDO_USER)/virtiofs-${VM_NAME}.sock"
# FIXME: This does not work. In windows, there is no virtiofs device.
# In GNU/Linux it's only readable.
#
#if ! systemctl -q is-active virtiofs-${VM_NAME}.socket ; then
# systemd-run --unit=virtiofs-${VM_NAME} \
# --slice=system-virtiofs \
# --collect \
# --socket-property=ListenStream="$socket" \
# --socket-property=Accept=no \
# --socket-property=SocketMode=0700 \
# --socket-property=SocketUser=${SUDO_USER} \
# --property=Type=exec \
# --property=StandardInput=socket \
# /usr/local/bin/virtiofsd --log-level debug --sandbox none \
# --syslog --fd=0 --shared-dir "/lmn/media/${SUDO_USER}"
#else
# systemctl restart virtiofs-${VM_NAME}.socket
#fi
if [[ ! -S "$socket" ]] ; then
systemd-run --unit=virtiofs-${VM_NAME} \
--slice=system-virtiofs \
--collect \
--property=Type=exec \
--property=SuccessExitStatus=1 \
--property="ExecStopPost=rm $socket" \
/usr/local/bin/virtiofsd --socket-path "$socket" \
--shared-dir "/lmn/media/${SUDO_USER}"
fi
sleep 1
chown "${SUDO_USER}" "$socket"

View file

@ -1,16 +0,0 @@
[Unit]
Description=share home folders via virtiofsd
## $I is split into two parameters: VM:USER
[Service]
Type=exec
ExecStartPre=/usr/bin/mkdir -p /run/virtiofs/
ExecStart=/usr/bin/sh -c 'v="%i"; soc="$${v%%:*}"; usr="$${v##*:}"; exec /usr/local/bin/virtiofsd --announce-submounts --socket-path="/run/virtiofs/$${soc}.sock" --shared-dir "/lmn/media/$${usr}"'
ExecStartPost=/usr/bin/sleep 1
ExecStartPost=/usr/bin/chmod 755 /run/virtiofs/
ExecStartPost=/usr/bin/sh -c 'v="%i"; soc="$${v%%:*}"; usr="$${v##*:}"; chown "$$usr" "/run/virtiofs/$${soc}.sock"'
ExecStopPost=/usr/bin/sh -c 'v="%i"; soc="$${v%%:*}"; rm "/run/virtiofs/$${soc}.sock"'
SuccessExitStatus=1
[Install]
WantedBy=multi-user.target

View file

@ -152,10 +152,10 @@
mode: '0644' mode: '0644'
notify: "enable vmimage-torrent.service" notify: "enable vmimage-torrent.service"
- name: Deploy virtiofs service - name: Remove virtiofs service
copy: file:
src: virtiofs@.service path: /etc/systemd/system/virtiofs@.service
dest: /etc/systemd/system/ state: absent
- name: Deploy bridge.conf needed for qemu session mode - name: Deploy bridge.conf needed for qemu session mode
lineinfile: lineinfile: