Bash Wie Trap programmieren?

CyborgBeta

Commander
Registriert
Jan. 2021
Beiträge
2.582
Hi,

ich muss tigervncserver -kill :* ausführen, wenn ein Docker-Container gestoppt wird, und brauche dafür eine Trap (also eine Art Shutdown-Hook), die auf SIGINT oder SIGHUP reagiert lauscht.

Wie programmiert man die Trap richtig?

Bisher habe ich Folgendes:

novnc-debian/Dockerfile:

Code:
FROM debian:12

ENV TZ=Europe/Berlin

EXPOSE 6901

RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
RUN apt update
RUN apt upgrade -y
RUN apt install nano net-tools git -y
RUN apt install lxde -y
RUN apt install tigervnc-standalone-server -y
RUN apt install dbus-x11 -y
RUN adduser --disabled-password --gecos "" headless
RUN echo "root:no"|chpasswd

RUN apt install firefox-esr -y
RUN apt clean

CMD [ "sh", "-c", "cd /home/headless/ && (git -C noVNC pull || git clone https://github.com/novnc/noVNC.git noVNC) && tigervncserver -localhost yes -SecurityTypes None -geometry 1600x900 && cd noVNC/ && (nohup ./utils/novnc_proxy --vnc localhost:5901 --listen 6901 &) && trap '{ tigervncserver -kill :*; }' 1 && while : ; do sleep 1 ; done" ]

docker-compose.yml:

Code:
  novnc-debian:
    build: ./novnc-debian/Dockerfile
    init: true
    stop_signal: SIGHUP
    user: 1000:1000
    ports:
      - 6901:6901
    volumes:
      - ./novnc-debian/headless/:/home/headless/

Hinweis, vorsichtshalber bitte nicht ohne NAT testen, da 6901 exposed wird und kein Passwort verwendet wird ...

Ist

&& trap '{ tigervncserver -kill :*; }' 1 && while : ; do sleep 1 ; done

richtig?

Danke für Antworten.

Edit: Ich knüpfe damit an dieses Thema an https://www.computerbase.de/forum/threads/wie-erlange-ich-hier-root-debian.2211540/
 
Zurück
Oben