mirror of
https://github.com/vdsm/virtual-dsm.git
synced 2025-11-07 02:23:42 +08:00
Compare commits
20 Commits
v7.38
...
fd5ec52226
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fd5ec52226 | ||
|
|
fc7ab22741 | ||
|
|
59cf59faa4 | ||
|
|
705c6ce7f1 | ||
|
|
f2937ab507 | ||
|
|
399829cf3c | ||
|
|
b694d6faf8 | ||
|
|
7acd1f6cdb | ||
|
|
09ca3bf118 | ||
|
|
6cac45c397 | ||
|
|
f18663d840 | ||
|
|
fefe1af9e6 | ||
|
|
87a8cf7513 | ||
|
|
7f31cb6023 | ||
|
|
138742c953 | ||
|
|
2c6efc45f2 | ||
|
|
24d795fbe3 | ||
|
|
7fae62d286 | ||
|
|
2135df07ea | ||
|
|
521beedf1c |
2
.github/workflows/hub.yml
vendored
2
.github/workflows/hub.yml
vendored
@@ -15,7 +15,7 @@ jobs:
|
||||
- uses: actions/checkout@v5
|
||||
-
|
||||
name: Docker Hub Description
|
||||
uses: peter-evans/dockerhub-description@v4
|
||||
uses: peter-evans/dockerhub-description@v5
|
||||
with:
|
||||
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||
|
||||
@@ -11,6 +11,7 @@ FROM qemux/qemu-host:2.05 AS builder
|
||||
|
||||
FROM debian:trixie-slim
|
||||
|
||||
ARG TARGETARCH
|
||||
ARG TARGETPLATFORM
|
||||
ARG VERSION_ARG="0.0"
|
||||
ARG DEBCONF_NOWARNINGS="yes"
|
||||
@@ -28,6 +29,7 @@ RUN set -eu && \
|
||||
unzip \
|
||||
nginx \
|
||||
procps \
|
||||
ethtool \
|
||||
python3 \
|
||||
python3-pip \
|
||||
python3-msgpack \
|
||||
@@ -45,6 +47,8 @@ RUN set -eu && \
|
||||
ca-certificates \
|
||||
netcat-openbsd \
|
||||
qemu-system-x86 && \
|
||||
wget "https://github.com/qemus/passt/releases/download/v2025_09_19/passt_2025_09_19_${TARGETARCH}.deb" -O /tmp/passt.deb -q && \
|
||||
dpkg -i /tmp/passt.deb && \
|
||||
apt-get clean && \
|
||||
pip3 install --no-cache-dir --break-system-packages --root-user-action=ignore dissect.cstruct && \
|
||||
mkdir -p /etc/qemu && \
|
||||
@@ -57,7 +61,7 @@ RUN set -eu && \
|
||||
COPY --chmod=755 ./src /run/
|
||||
COPY --chmod=755 ./web /var/www/
|
||||
COPY --chmod=755 --from=builder /qemu-host.bin /run/host.bin
|
||||
COPY --chmod=744 ./web/conf/nginx.conf /etc/nginx/sites-enabled/web.conf
|
||||
COPY --chmod=744 ./web/conf/nginx.conf /etc/nginx/default.conf
|
||||
ADD --chmod=775 https://raw.githubusercontent.com/sud0woodo/patology/refs/heads/main/patology.py /run/extract.py
|
||||
|
||||
VOLUME /storage
|
||||
@@ -65,7 +69,7 @@ EXPOSE 22 139 445 5000
|
||||
|
||||
ENV RAM_SIZE="2G"
|
||||
ENV CPU_CORES="2"
|
||||
ENV DISK_SIZE="16G"
|
||||
ENV DISK_SIZE="256G"
|
||||
|
||||
HEALTHCHECK --interval=60s --start-period=45s --retries=2 CMD /run/check.sh
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ services:
|
||||
container_name: dsm
|
||||
image: vdsm/virtual-dsm
|
||||
environment:
|
||||
DISK_SIZE: "16G"
|
||||
DISK_SIZE: "256G"
|
||||
devices:
|
||||
- /dev/kvm
|
||||
- /dev/net/tun
|
||||
|
||||
@@ -8,7 +8,7 @@ spec:
|
||||
- ReadWriteOnce
|
||||
resources:
|
||||
requests:
|
||||
storage: 16Gi
|
||||
storage: 256Gi
|
||||
---
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
@@ -31,7 +31,7 @@ spec:
|
||||
image: vdsm/virtual-dsm
|
||||
env:
|
||||
- name: DISK_SIZE
|
||||
value: "16G"
|
||||
value: "256G"
|
||||
ports:
|
||||
- containerPort: 5000
|
||||
name: http
|
||||
|
||||
31
readme.md
31
readme.md
@@ -30,7 +30,7 @@ services:
|
||||
container_name: dsm
|
||||
image: vdsm/virtual-dsm
|
||||
environment:
|
||||
DISK_SIZE: "16G"
|
||||
DISK_SIZE: "256G"
|
||||
devices:
|
||||
- /dev/kvm
|
||||
- /dev/net/tun
|
||||
@@ -47,7 +47,7 @@ services:
|
||||
##### Via Docker CLI:
|
||||
|
||||
```bash
|
||||
docker run -it --rm --name dsm -p 5000:5000 --device=/dev/kvm --device=/dev/net/tun --cap-add NET_ADMIN -v "${PWD:-.}/dsm:/storage" --stop-timeout 120 vdsm/virtual-dsm
|
||||
docker run -it --rm --name dsm -e "DISK_SIZE=256G" -p 5000:5000 --device=/dev/kvm --device=/dev/net/tun --cap-add NET_ADMIN -v "${PWD:-.}/dsm:/storage" --stop-timeout 120 vdsm/virtual-dsm
|
||||
```
|
||||
|
||||
##### Via Kubernetes:
|
||||
@@ -87,35 +87,24 @@ kubectl apply -f https://raw.githubusercontent.com/vdsm/virtual-dsm/refs/heads/m
|
||||
|
||||
### How do I change the size of the disk?
|
||||
|
||||
To expand the default size of 16 GB, locate the `DISK_SIZE` setting in your compose file and modify it to your preferred capacity:
|
||||
To expand the default size of 256 GB, locate the `DISK_SIZE` setting in your compose file and modify it to your preferred capacity:
|
||||
|
||||
```yaml
|
||||
environment:
|
||||
DISK_SIZE: "128G"
|
||||
DISK_SIZE: "512G"
|
||||
```
|
||||
|
||||
> [!TIP]
|
||||
> This can also be used to resize the existing disk to a larger capacity without any data loss.
|
||||
|
||||
### How do I create a growable disk?
|
||||
|
||||
By default, the entire capacity of the disk will be reserved in advance.
|
||||
|
||||
To create a growable disk that only allocates space that is actually used, add the following environment variable:
|
||||
|
||||
```yaml
|
||||
environment:
|
||||
DISK_FMT: "qcow2"
|
||||
```
|
||||
|
||||
### How do I add multiple disks?
|
||||
|
||||
To create additional disks, modify your compose file like this:
|
||||
|
||||
```yaml
|
||||
environment:
|
||||
DISK2_SIZE: "32G"
|
||||
DISK3_SIZE: "64G"
|
||||
DISK2_SIZE: "500G"
|
||||
DISK3_SIZE: "750G"
|
||||
volumes:
|
||||
- ./example2:/storage2
|
||||
- ./example3:/storage3
|
||||
@@ -263,14 +252,6 @@ kubectl apply -f https://raw.githubusercontent.com/vdsm/virtual-dsm/refs/heads/m
|
||||
|
||||
There are only two minor differences: the Virtual Machine Manager package is not available, and Surveillance Station will not include any free licenses.
|
||||
|
||||
### How do I run Windows in a container?
|
||||
|
||||
You can use [dockur/windows](https://github.com/dockur/windows) for that. It shares many of the same features, and even has completely automatic installation.
|
||||
|
||||
### How do I run a Linux desktop in a container?
|
||||
|
||||
You can use [qemus/qemu](https://github.com/qemus/qemu) in that case.
|
||||
|
||||
### Is this project legal?
|
||||
|
||||
Yes, this project contains only open-source code and does not distribute any copyrighted material. Neither does it try to circumvent any copyright protection measures. So under all applicable laws, this project will be considered legal.
|
||||
|
||||
@@ -37,7 +37,7 @@ if [[ "$RAM_CHECK" != [Nn]* ]]; then
|
||||
fi
|
||||
|
||||
if [[ "$DEBUG" == [Yy1]* ]]; then
|
||||
printf "Arguments:\n\n%s\n\n" "${ARGS// -/$'\n-'}"
|
||||
printf "QEMU arguments:\n\n%s\n\n" "${ARGS// -/$'\n-'}"
|
||||
fi
|
||||
|
||||
return 0
|
||||
|
||||
20
src/disk.sh
20
src/disk.sh
@@ -507,12 +507,8 @@ addDevice () {
|
||||
physical="${physical%% *}"
|
||||
|
||||
if [ -n "$physical" ]; then
|
||||
if [[ "$physical" == "512" || "$physical" == "4096" ]]; then
|
||||
if [[ "$physical" == "4096" ]]; then
|
||||
sectors=",logical_block_size=$logical,physical_block_size=$physical"
|
||||
fi
|
||||
else
|
||||
warn "Unknown physical sector size: $physical for $DISK_DEV"
|
||||
if [[ "$physical" != "512" ]]; then
|
||||
sectors=",logical_block_size=$logical,physical_block_size=$physical"
|
||||
fi
|
||||
else
|
||||
warn "Failed to determine the sector size for $DISK_DEV"
|
||||
@@ -523,7 +519,9 @@ addDevice () {
|
||||
return 0
|
||||
}
|
||||
|
||||
html "Initializing disks..."
|
||||
msg="Initializing disks..."
|
||||
html "$msg"
|
||||
[[ "$DEBUG" == [Yy1]* ]] && echo "$msg"
|
||||
|
||||
[ -z "${DISK_OPTS:-}" ] && DISK_OPTS=""
|
||||
[ -z "${DISK_TYPE:-}" ] && DISK_TYPE="scsi"
|
||||
@@ -535,11 +533,7 @@ case "${DISK_TYPE,,}" in
|
||||
esac
|
||||
|
||||
if [ -z "$ALLOCATE" ]; then
|
||||
if [[ "${DISK_FMT,,}" == "raw" ]]; then
|
||||
ALLOCATE="Y"
|
||||
else
|
||||
ALLOCATE="N"
|
||||
fi
|
||||
ALLOCATE="N"
|
||||
fi
|
||||
|
||||
if [[ "$ALLOCATE" == [Nn]* ]]; then
|
||||
@@ -554,7 +548,7 @@ DISK_OPTS+=$(createDevice "$BOOT" "$DISK_TYPE" "1" "0xa" "raw" "$DISK_IO" "$DISK
|
||||
DISK_OPTS+=$(createDevice "$SYSTEM" "$DISK_TYPE" "2" "0xb" "raw" "$DISK_IO" "$DISK_CACHE" "" "")
|
||||
|
||||
DISK1_FILE="$STORAGE/${DISK_NAME}"
|
||||
if [[ ! -f "$DISK1_FILE.img" && -f "$STORAGE/data${DISK_SIZE}.img" ]]; then
|
||||
if [ ! -f "$DISK1_FILE.img" ] && [ -f "$STORAGE/data${DISK_SIZE}.img" ]; then
|
||||
# Fallback for legacy installs
|
||||
mv "$STORAGE/data${DISK_SIZE}.img" "$DISK1_FILE.img"
|
||||
fi
|
||||
|
||||
@@ -18,6 +18,10 @@ if [[ "$GPU" != [Yy1]* || "$CPU_VENDOR" != "GenuineIntel" || "$ARCH" != "amd64"
|
||||
|
||||
fi
|
||||
|
||||
msg="Configuring display drivers..."
|
||||
html "$msg"
|
||||
[[ "$DEBUG" == [Yy1]* ]] && echo "$msg"
|
||||
|
||||
DISPLAY_OPTS="-display egl-headless,rendernode=$RENDERNODE"
|
||||
DISPLAY_OPTS+=" -vga $VGA"
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ set -Eeuo pipefail
|
||||
|
||||
cd /run
|
||||
|
||||
. start.sh # Placeholder
|
||||
. utils.sh # Load functions
|
||||
. reset.sh # Initialize system
|
||||
. install.sh # Run installation
|
||||
|
||||
@@ -31,8 +31,9 @@ if [ -n "$URL" ] && [ ! -s "$FILE" ] && [ ! -d "$DIR" ]; then
|
||||
BASE=$(basename "$URL" .pat)
|
||||
if [ ! -s "$STORAGE/$BASE.system.img" ]; then
|
||||
BASE=$(basename "${URL%%\?*}" .pat)
|
||||
: "${BASE//+/ }"; printf -v BASE '%b' "${_//%/\\x}"
|
||||
BASE=$(echo "$BASE" | sed -e 's/[^A-Za-z0-9._-]/_/g')
|
||||
BASE="${BASE//+/ }"
|
||||
printf -v BASE '%b' "${BASE//%/\\x}"
|
||||
BASE="${BASE//[!A-Za-z0-9._-]/_}"
|
||||
fi
|
||||
if [[ "${URL,,}" != "http"* && "${URL,,}" != "file:"* ]] ; then
|
||||
[ ! -s "$STORAGE/$BASE.pat" ] && error "Invalid URL: $URL" && exit 65
|
||||
@@ -65,8 +66,9 @@ fi
|
||||
|
||||
if [ ! -s "$FILE" ]; then
|
||||
BASE=$(basename "${URL%%\?*}" .pat)
|
||||
: "${BASE//+/ }"; printf -v BASE '%b' "${_//%/\\x}"
|
||||
BASE=$(echo "$BASE" | sed -e 's/[^A-Za-z0-9._-]/_/g')
|
||||
BASE="${BASE//+/ }"
|
||||
printf -v BASE '%b' "${BASE//%/\\x}"
|
||||
BASE="${BASE//[!A-Za-z0-9._-]/_}"
|
||||
fi
|
||||
|
||||
if [[ "$URL" != "file://$STORAGE/$BASE.pat" ]]; then
|
||||
|
||||
487
src/network.sh
487
src/network.sh
@@ -7,17 +7,24 @@ set -Eeuo pipefail
|
||||
: "${MTU:=""}"
|
||||
: "${DHCP:="N"}"
|
||||
: "${NETWORK:="Y"}"
|
||||
: "${USER_PORTS:=""}"
|
||||
: "${HOST_PORTS:=""}"
|
||||
: "${USER_PORTS:=""}"
|
||||
: "${ADAPTER:="virtio-net-pci"}"
|
||||
|
||||
: "${VM_NET_IP:=""}"
|
||||
: "${VM_NET_DEV:=""}"
|
||||
: "${VM_NET_TAP:="dsm"}"
|
||||
: "${VM_NET_MAC:="$MAC"}"
|
||||
: "${VM_NET_IP:="20.20.20.21"}"
|
||||
: "${VM_NET_BRIDGE:="docker"}"
|
||||
: "${VM_NET_HOST:="VirtualDSM"}"
|
||||
: "${VM_NET_MASK:="255.255.255.0"}"
|
||||
|
||||
: "${PASST:="passt"}"
|
||||
: "${PASST_OPTS:=""}"
|
||||
: "${PASST_DEBUG:=""}"
|
||||
|
||||
: "${DNSMASQ_OPTS:=""}"
|
||||
: "${DNSMASQ_DEBUG:=""}"
|
||||
: "${DNSMASQ:="/usr/sbin/dnsmasq"}"
|
||||
: "${DNSMASQ_CONF_DIR:="/etc/dnsmasq.d"}"
|
||||
|
||||
@@ -29,6 +36,8 @@ ADD_ERR="Please add the following setting to your container:"
|
||||
|
||||
configureDHCP() {
|
||||
|
||||
[[ "$DEBUG" == [Yy1]* ]] && echo "Configuring MACVTAP networking..."
|
||||
|
||||
# Create the necessary file structure for /dev/vhost-net
|
||||
if [ ! -c /dev/vhost-net ]; then
|
||||
if mknod /dev/vhost-net c 10 238; then
|
||||
@@ -61,12 +70,13 @@ configureDHCP() {
|
||||
|
||||
if [[ "$MTU" != "0" && "$MTU" != "1500" ]]; then
|
||||
if ! ip link set dev "$VM_NET_TAP" mtu "$MTU"; then
|
||||
warn "Failed to set MTU size.."
|
||||
warn "Failed to set MTU size to $MTU."
|
||||
fi
|
||||
fi
|
||||
|
||||
while ! ip link set "$VM_NET_TAP" up; do
|
||||
info "Waiting for MAC address $VM_NET_MAC to become available..."
|
||||
info "If you cloned this machine, please delete the 'dsm.mac' file to generate a different MAC address."
|
||||
sleep 2
|
||||
done
|
||||
|
||||
@@ -104,35 +114,67 @@ configureDHCP() {
|
||||
|
||||
configureDNS() {
|
||||
|
||||
# Create lease file for faster resolve
|
||||
echo "0 $VM_NET_MAC $VM_NET_IP $VM_NET_HOST 01:$VM_NET_MAC" > /var/lib/misc/dnsmasq.leases
|
||||
chmod 644 /var/lib/misc/dnsmasq.leases
|
||||
local if="$1"
|
||||
local ip="$2"
|
||||
local mac="$3"
|
||||
local host="$4"
|
||||
local mask="$5"
|
||||
local gateway="$6"
|
||||
|
||||
# dnsmasq configuration:
|
||||
DNSMASQ_OPTS+=" --dhcp-authoritative"
|
||||
[[ "${DNSMASQ_DISABLE:-}" == [Yy1]* ]] && return 0
|
||||
[[ "$DEBUG" == [Yy1]* ]] && echo "Starting dnsmasq daemon..."
|
||||
|
||||
# Set DHCP range and host
|
||||
DNSMASQ_OPTS+=" --dhcp-range=$VM_NET_IP,$VM_NET_IP"
|
||||
DNSMASQ_OPTS+=" --dhcp-host=$VM_NET_MAC,,$VM_NET_IP,$VM_NET_HOST,infinite"
|
||||
local log="/var/log/dnsmasq.log"
|
||||
rm -f "$log"
|
||||
|
||||
# Set DNS server and gateway
|
||||
DNSMASQ_OPTS+=" --dhcp-option=option:netmask,255.255.255.0"
|
||||
DNSMASQ_OPTS+=" --dhcp-option=option:router,${VM_NET_IP%.*}.1"
|
||||
DNSMASQ_OPTS+=" --dhcp-option=option:dns-server,${VM_NET_IP%.*}.1"
|
||||
case "${NETWORK,,}" in
|
||||
"nat" | "tap" | "tun" | "tuntap" | "y" )
|
||||
|
||||
# Create lease file for faster resolve
|
||||
echo "0 $mac $ip $host 01:$mac" > /var/lib/misc/dnsmasq.leases
|
||||
chmod 644 /var/lib/misc/dnsmasq.leases
|
||||
|
||||
# dnsmasq configuration:
|
||||
DNSMASQ_OPTS+=" --dhcp-authoritative"
|
||||
|
||||
# Set DHCP range and host
|
||||
DNSMASQ_OPTS+=" --dhcp-range=$ip,$ip"
|
||||
DNSMASQ_OPTS+=" --dhcp-host=$mac,,$ip,$host,infinite"
|
||||
|
||||
# Set DNS server and gateway
|
||||
DNSMASQ_OPTS+=" --dhcp-option=option:netmask,$mask"
|
||||
DNSMASQ_OPTS+=" --dhcp-option=option:router,$gateway"
|
||||
DNSMASQ_OPTS+=" --dhcp-option=option:dns-server,$gateway"
|
||||
|
||||
esac
|
||||
|
||||
# Set interfaces
|
||||
DNSMASQ_OPTS+=" --interface=$if"
|
||||
DNSMASQ_OPTS+=" --bind-interfaces"
|
||||
|
||||
# Add DNS entry for container
|
||||
DNSMASQ_OPTS+=" --address=/host.lan/${VM_NET_IP%.*}.1"
|
||||
DNSMASQ_OPTS+=" --address=/host.lan/$gateway"
|
||||
|
||||
# Set local dns resolver to dnsmasq when needed
|
||||
[ -f /etc/resolv.dnsmasq ] && DNSMASQ_OPTS+=" --resolv-file=/etc/resolv.dnsmasq"
|
||||
|
||||
# Enable logging to file
|
||||
DNSMASQ_OPTS+=" --log-facility=$log"
|
||||
|
||||
DNSMASQ_OPTS=$(echo "$DNSMASQ_OPTS" | sed 's/\t/ /g' | tr -s ' ' | sed 's/^ *//')
|
||||
|
||||
if [[ "${DEBUG_DNS:-}" == [Yy1]* ]]; then
|
||||
DNSMASQ_OPTS+=" -d"
|
||||
$DNSMASQ ${DNSMASQ_OPTS:+ $DNSMASQ_OPTS} &
|
||||
return 0
|
||||
fi
|
||||
[[ "$DEBUG" == [Yy1]* ]] && printf "Dnsmasq arguments:\n\n%s\n\n" "${DNSMASQ_OPTS// -/$'\n-'}"
|
||||
|
||||
if ! $DNSMASQ ${DNSMASQ_OPTS:+ $DNSMASQ_OPTS}; then
|
||||
error "Failed to start dnsmasq, reason: $?" && return 1
|
||||
|
||||
local msg="Failed to start Dnsmasq, reason: $?"
|
||||
[ -f "$log" ] && cat "$log"
|
||||
error "$msg"
|
||||
|
||||
return 1
|
||||
fi
|
||||
|
||||
if [[ "$DNSMASQ_DEBUG" == [Yy1]* ]]; then
|
||||
tail -fn +0 "$log" &
|
||||
fi
|
||||
|
||||
return 0
|
||||
@@ -172,38 +214,137 @@ getUserPorts() {
|
||||
|
||||
getHostPorts() {
|
||||
|
||||
local list=$1
|
||||
local list="$1"
|
||||
list=$(echo "${list// /}" | sed 's/,*$//g')
|
||||
|
||||
[ -z "$list" ] && echo "" && return 0
|
||||
[ -z "$list" ] && list="$MON_PORT" || list+=",$MON_PORT"
|
||||
|
||||
if [[ "${NETWORK,,}" == "passt" ]]; then
|
||||
|
||||
local DNS_PORT="53"
|
||||
|
||||
if [[ "${DNSMASQ_DISABLE:-}" != [Yy1]* ]]; then
|
||||
[ -z "$list" ] && list="$DNS_PORT" || list+=",$DNS_PORT"
|
||||
fi
|
||||
|
||||
[ -z "$list" ] && list="$COM_PORT" || list+=",$COM_PORT"
|
||||
[ -z "$list" ] && list="$CHR_PORT" || list+=",$CHR_PORT"
|
||||
|
||||
if [[ "$list" != *","* ]]; then
|
||||
echo " ! --dport $list"
|
||||
else
|
||||
echo " -m multiport ! --dports $list"
|
||||
fi
|
||||
|
||||
echo "$list"
|
||||
return 0
|
||||
}
|
||||
|
||||
configureUser() {
|
||||
configureSlirp() {
|
||||
|
||||
if [ -z "$IP6" ]; then
|
||||
NET_OPTS="-netdev user,id=hostnet0,host=${VM_NET_IP%.*}.1,net=${VM_NET_IP%.*}.0/24,dhcpstart=$VM_NET_IP,hostname=$VM_NET_HOST"
|
||||
else
|
||||
NET_OPTS="-netdev user,id=hostnet0,ipv4=on,host=${VM_NET_IP%.*}.1,net=${VM_NET_IP%.*}.0/24,dhcpstart=$VM_NET_IP,ipv6=on,hostname=$VM_NET_HOST"
|
||||
fi
|
||||
[[ "$DEBUG" == [Yy1]* ]] && echo "Configuring slirp networking..."
|
||||
|
||||
local ip="$IP"
|
||||
[ -n "$VM_NET_IP" ] && ip="$VM_NET_IP"
|
||||
local base="${ip%.*}."
|
||||
[ "${ip/$base/}" -lt "4" ] && ip="${ip%.*}.4"
|
||||
local gateway="${ip%.*}.1"
|
||||
|
||||
local ipv6=""
|
||||
[ -n "$IP6" ] && ipv6="ipv6=on,"
|
||||
|
||||
NET_OPTS="-netdev user,id=hostnet0,ipv4=on,host=$gateway,net=${gateway%.*}.0/24,dhcpstart=$ip,${ipv6}hostname=$VM_NET_HOST"
|
||||
|
||||
local forward
|
||||
forward=$(getUserPorts "$USER_PORTS")
|
||||
forward=$(getUserPorts "${USER_PORTS:-}")
|
||||
[ -n "$forward" ] && NET_OPTS+=",$forward"
|
||||
|
||||
if [[ "${DNSMASQ_DISABLE:-}" != [Yy1]* ]]; then
|
||||
cp /etc/resolv.conf /etc/resolv.dnsmasq
|
||||
echo -e "nameserver 127.0.0.1\nsearch .\noptions ndots:0" >/etc/resolv.conf
|
||||
configureDNS "lo" "$ip" "$VM_NET_MAC" "$VM_NET_HOST" "$VM_NET_MASK" "$gateway" || return 1
|
||||
fi
|
||||
|
||||
VM_NET_IP="$ip"
|
||||
return 0
|
||||
}
|
||||
|
||||
configurePasst() {
|
||||
|
||||
[[ "$DEBUG" == [Yy1]* ]] && echo "Configuring user-mode networking..."
|
||||
|
||||
local log="/var/log/passt.log"
|
||||
rm -f "$log"
|
||||
|
||||
local pid="/var/run/dnsmasq.pid"
|
||||
[ -s "$pid" ] && pKill "$(<"$pid")"
|
||||
|
||||
local ip="$IP"
|
||||
[ -n "$VM_NET_IP" ] && ip="$VM_NET_IP"
|
||||
|
||||
local gateway=""
|
||||
if [[ "$ip" != *".1" ]]; then
|
||||
gateway="${ip%.*}.1"
|
||||
else
|
||||
gateway="${ip%.*}.2"
|
||||
fi
|
||||
|
||||
# passt configuration:
|
||||
[ -z "$IP6" ] && PASST_OPTS+=" -4"
|
||||
|
||||
PASST_OPTS+=" -a $ip"
|
||||
PASST_OPTS+=" -g $gateway"
|
||||
PASST_OPTS+=" -n $VM_NET_MASK"
|
||||
|
||||
exclude=$(getHostPorts "$HOST_PORTS")
|
||||
|
||||
if [ -z "$exclude" ]; then
|
||||
exclude="all"
|
||||
else
|
||||
exclude="~${exclude//,/,~}"
|
||||
fi
|
||||
|
||||
PASST_OPTS+=" -t $exclude"
|
||||
PASST_OPTS+=" -u $exclude"
|
||||
PASST_OPTS+=" -H $VM_NET_HOST"
|
||||
PASST_OPTS+=" -M $GATEWAY_MAC"
|
||||
PASST_OPTS+=" -P /var/run/passt.pid"
|
||||
PASST_OPTS+=" -l $log"
|
||||
PASST_OPTS+=" -q"
|
||||
|
||||
if [[ "${DNSMASQ_DISABLE:-}" != [Yy1]* ]]; then
|
||||
cp /etc/resolv.conf /etc/resolv.dnsmasq
|
||||
echo -e "nameserver 127.0.0.1\nsearch .\noptions ndots:0" >/etc/resolv.conf
|
||||
fi
|
||||
|
||||
PASST_OPTS=$(echo "$PASST_OPTS" | sed 's/\t/ /g' | tr -s ' ' | sed 's/^ *//')
|
||||
[[ "$DEBUG" == [Yy1]* ]] && printf "Passt arguments:\n\n%s\n\n" "${PASST_OPTS// -/$'\n-'}"
|
||||
|
||||
if ! $PASST ${PASST_OPTS:+ $PASST_OPTS} >/dev/null 2>&1; then
|
||||
local msg="Failed to start passt, reason: $?"
|
||||
[ -f "$log" ] && cat "$log"
|
||||
error "$msg"
|
||||
return 1
|
||||
fi
|
||||
|
||||
if [[ "$PASST_DEBUG" == [Yy1]* ]]; then
|
||||
tail -fn +0 "$log" &
|
||||
else
|
||||
if [[ "$DEBUG" == [Yy1]* ]]; then
|
||||
[ -f "$log" ] && cat "$log" && echo ""
|
||||
fi
|
||||
fi
|
||||
|
||||
NET_OPTS="-netdev stream,id=hostnet0,server=off,addr.type=unix,addr.path=/tmp/passt_1.socket"
|
||||
|
||||
configureDNS "lo" "$ip" "$VM_NET_MAC" "$VM_NET_HOST" "$VM_NET_MASK" "$gateway" || return 1
|
||||
|
||||
VM_NET_IP="$ip"
|
||||
return 0
|
||||
}
|
||||
|
||||
configureNAT() {
|
||||
|
||||
local tuntap="TUN device is missing. $ADD_ERR --device /dev/net/tun"
|
||||
local tables="The 'ip_tables' kernel module is not loaded. Try this command: sudo modprobe ip_tables iptable_nat"
|
||||
local tables="the 'ip_tables' kernel module is not loaded. Try this command: sudo modprobe ip_tables iptable_nat"
|
||||
|
||||
[[ "$DEBUG" == [Yy1]* ]] && echo "Configuring NAT networking..."
|
||||
|
||||
# Create the necessary file structure for /dev/net/tun
|
||||
if [ ! -c /dev/net/tun ]; then
|
||||
@@ -215,50 +356,57 @@ configureNAT() {
|
||||
fi
|
||||
|
||||
if [ ! -c /dev/net/tun ]; then
|
||||
error "$tuntap" && return 1
|
||||
warn "$tuntap" && return 1
|
||||
fi
|
||||
|
||||
# Check port forwarding flag
|
||||
if [[ $(< /proc/sys/net/ipv4/ip_forward) -eq 0 ]]; then
|
||||
{ sysctl -w net.ipv4.ip_forward=1 > /dev/null 2>&1; rc=$?; } || :
|
||||
if (( rc != 0 )) || [[ $(< /proc/sys/net/ipv4/ip_forward) -eq 0 ]]; then
|
||||
[[ "$PODMAN" == [Yy1]* ]] && return 1
|
||||
error "IP forwarding is disabled. $ADD_ERR --sysctl net.ipv4.ip_forward=1"
|
||||
warn "IP forwarding is disabled. $ADD_ERR --sysctl net.ipv4.ip_forward=1"
|
||||
return 1
|
||||
fi
|
||||
fi
|
||||
|
||||
local ip="172.30.0.2"
|
||||
[ -n "$VM_NET_IP" ] && ip="$VM_NET_IP"
|
||||
|
||||
local gateway=""
|
||||
if [[ "$ip" != *".1" ]]; then
|
||||
gateway="${ip%.*}.1"
|
||||
else
|
||||
gateway="${ip%.*}.2"
|
||||
fi
|
||||
|
||||
# Create a bridge with a static IP for the VM guest
|
||||
{ ip link add dev dockerbridge type bridge ; rc=$?; } || :
|
||||
{ ip link add dev "$VM_NET_BRIDGE" type bridge ; rc=$?; } || :
|
||||
|
||||
if (( rc != 0 )); then
|
||||
error "Failed to create bridge. $ADD_ERR --cap-add NET_ADMIN" && return 1
|
||||
warn "failed to create bridge. $ADD_ERR --cap-add NET_ADMIN" && return 1
|
||||
fi
|
||||
|
||||
if ! ip address add "${VM_NET_IP%.*}.1/24" broadcast "${VM_NET_IP%.*}.255" dev dockerbridge; then
|
||||
error "Failed to add IP address pool!" && return 1
|
||||
if ! ip address add "$gateway/24" broadcast "${ip%.*}.255" dev "$VM_NET_BRIDGE"; then
|
||||
warn "failed to add IP address pool!" && return 1
|
||||
fi
|
||||
|
||||
while ! ip link set dockerbridge up; do
|
||||
while ! ip link set "$VM_NET_BRIDGE" up; do
|
||||
info "Waiting for IP address to become available..."
|
||||
sleep 2
|
||||
done
|
||||
|
||||
# QEMU Works with taps, set tap to the bridge created
|
||||
if ! ip tuntap add dev "$VM_NET_TAP" mode tap; then
|
||||
error "$tuntap" && return 1
|
||||
warn "$tuntap" && return 1
|
||||
fi
|
||||
|
||||
if [[ "$MTU" != "0" && "$MTU" != "1500" ]]; then
|
||||
if ! ip link set dev "$VM_NET_TAP" mtu "$MTU"; then
|
||||
warn "Failed to set MTU size.."
|
||||
warn "failed to set MTU size to $MTU."
|
||||
fi
|
||||
fi
|
||||
|
||||
GATEWAY_MAC=$(echo "$VM_NET_MAC" | md5sum | sed 's/^\(..\)\(..\)\(..\)\(..\)\(..\).*$/02:\1:\2:\3:\4:\5/')
|
||||
|
||||
if ! ip link set dev "$VM_NET_TAP" address "$GATEWAY_MAC"; then
|
||||
warn "Failed to set gateway MAC address.."
|
||||
warn "failed to set gateway MAC address.."
|
||||
fi
|
||||
|
||||
while ! ip link set "$VM_NET_TAP" up promisc on; do
|
||||
@@ -266,27 +414,39 @@ configureNAT() {
|
||||
sleep 2
|
||||
done
|
||||
|
||||
if ! ip link set dev "$VM_NET_TAP" master dockerbridge; then
|
||||
error "Failed to set IP link!" && return 1
|
||||
if ! ip link set dev "$VM_NET_TAP" master "$VM_NET_BRIDGE"; then
|
||||
warn "failed to set master bridge!" && return 1
|
||||
fi
|
||||
|
||||
# Add internet connection to the VM
|
||||
update-alternatives --set iptables /usr/sbin/iptables-legacy > /dev/null
|
||||
update-alternatives --set ip6tables /usr/sbin/ip6tables-legacy > /dev/null
|
||||
if grep -wq "nf_tables" /proc/modules; then
|
||||
update-alternatives --set iptables /usr/sbin/iptables-nft > /dev/null
|
||||
update-alternatives --set ip6tables /usr/sbin/ip6tables-nft > /dev/null
|
||||
else
|
||||
update-alternatives --set iptables /usr/sbin/iptables-legacy > /dev/null
|
||||
update-alternatives --set ip6tables /usr/sbin/ip6tables-legacy > /dev/null
|
||||
fi
|
||||
|
||||
exclude=$(getHostPorts "$HOST_PORTS")
|
||||
|
||||
if [ -n "$exclude" ]; then
|
||||
if [[ "$exclude" != *","* ]]; then
|
||||
exclude=" ! --dport $exclude"
|
||||
else
|
||||
exclude=" -m multiport ! --dports $exclude"
|
||||
fi
|
||||
fi
|
||||
|
||||
if ! iptables -t nat -A POSTROUTING -o "$VM_NET_DEV" -j MASQUERADE; then
|
||||
error "$tables" && return 1
|
||||
warn "$tables" && return 1
|
||||
fi
|
||||
|
||||
# shellcheck disable=SC2086
|
||||
if ! iptables -t nat -A PREROUTING -i "$VM_NET_DEV" -d "$IP" -p tcp${exclude} -j DNAT --to "$VM_NET_IP"; then
|
||||
error "Failed to configure IP tables!" && return 1
|
||||
if ! iptables -t nat -A PREROUTING -i "$VM_NET_DEV" -d "$IP" -p tcp${exclude} -j DNAT --to "$ip"; then
|
||||
warn "failed to configure IP tables!" && return 1
|
||||
fi
|
||||
|
||||
if ! iptables -t nat -A PREROUTING -i "$VM_NET_DEV" -d "$IP" -p udp -j DNAT --to "$VM_NET_IP"; then
|
||||
error "Failed to configure IP tables!" && return 1
|
||||
if ! iptables -t nat -A PREROUTING -i "$VM_NET_DEV" -d "$IP" -p udp -j DNAT --to "$ip"; then
|
||||
warn "failed to configure IP tables!" && return 1
|
||||
fi
|
||||
|
||||
if (( KERNEL > 4 )); then
|
||||
@@ -303,8 +463,9 @@ configureNAT() {
|
||||
|
||||
NET_OPTS+=",script=no,downscript=no"
|
||||
|
||||
configureDNS || return 1
|
||||
configureDNS "$VM_NET_BRIDGE" "$ip" "$VM_NET_MAC" "$VM_NET_HOST" "$VM_NET_MASK" "$gateway" || return 1
|
||||
|
||||
VM_NET_IP="$ip"
|
||||
return 0
|
||||
}
|
||||
|
||||
@@ -312,14 +473,21 @@ closeBridge() {
|
||||
|
||||
local pid="/var/run/dnsmasq.pid"
|
||||
[ -s "$pid" ] && pKill "$(<"$pid")"
|
||||
rm -f "$pid"
|
||||
|
||||
[[ "${NETWORK,,}" == "user"* ]] && return 0
|
||||
pid="/var/run/passt.pid"
|
||||
[ -s "$pid" ] && pKill "$(<"$pid")"
|
||||
rm -f "$pid"
|
||||
|
||||
case "${NETWORK,,}" in
|
||||
"user"* | "passt" | "slirp" ) return 0 ;;
|
||||
esac
|
||||
|
||||
ip link set "$VM_NET_TAP" down promisc off &> null || true
|
||||
ip link delete "$VM_NET_TAP" &> null || true
|
||||
|
||||
ip link set dockerbridge down &> null || true
|
||||
ip link delete dockerbridge &> null || true
|
||||
ip link set "$VM_NET_BRIDGE" down &> null || true
|
||||
ip link delete "$VM_NET_BRIDGE" &> null || true
|
||||
|
||||
return 0
|
||||
}
|
||||
@@ -352,6 +520,21 @@ closeNetwork() {
|
||||
return 0
|
||||
}
|
||||
|
||||
cleanUp() {
|
||||
|
||||
# Clean up old files
|
||||
rm -f /etc/resolv.dnsmasq
|
||||
rm -f /var/run/passt.pid
|
||||
rm -f /var/run/dnsmasq.pid
|
||||
|
||||
if [[ -d "/sys/class/net/$VM_NET_TAP" ]]; then
|
||||
info "Lingering interface will be removed..."
|
||||
ip link delete "$VM_NET_TAP" || true
|
||||
fi
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
checkOS() {
|
||||
|
||||
local kernel
|
||||
@@ -392,18 +575,62 @@ getInfo() {
|
||||
error "$ADD_ERR -e \"VM_NET_DEV=NAME\" to specify another interface name." && exit 26
|
||||
fi
|
||||
|
||||
BASE_IP="${VM_NET_IP%.*}."
|
||||
GATEWAY=$(ip route list dev "$VM_NET_DEV" | awk ' /^default/ {print $3}' | head -n 1)
|
||||
IP=$(ip address show dev "$VM_NET_DEV" | grep inet | awk '/inet / { print $2 }' | cut -f1 -d/ | head -n 1)
|
||||
IP6=""
|
||||
|
||||
if [ "${VM_NET_IP/$BASE_IP/}" -lt "3" ]; then
|
||||
error "Invalid VM_NET_IP, must end in a higher number than .3" && exit 27
|
||||
# shellcheck disable=SC2143
|
||||
if [ -f /proc/net/if_inet6 ] && [ -n "$(ifconfig -a | grep inet6)" ]; then
|
||||
IP6=$(ip -6 addr show dev "$VM_NET_DEV" scope global up)
|
||||
[ -n "$IP6" ] && IP6=$(echo "$IP6" | sed -e's/^.*inet6 \([^ ]*\)\/.*$/\1/;t;d' | head -n 1)
|
||||
fi
|
||||
|
||||
if [ -z "$MTU" ]; then
|
||||
MTU=$(cat "/sys/class/net/$VM_NET_DEV/mtu")
|
||||
|
||||
local result nic bus
|
||||
result=$(ethtool -i "$VM_NET_DEV")
|
||||
nic=$(grep -m 1 -i 'driver:' <<< "$result" | awk '{print $(2)}')
|
||||
bus=$(grep -m 1 -i 'bus-info:' <<< "$result" | awk '{print $(2)}')
|
||||
|
||||
if [[ "${bus,,}" != "" && "${bus,,}" != "n/a" && "${bus,,}" != "tap" ]]; then
|
||||
[[ "$DEBUG" == [Yy1]* ]] && info "Detected BUS: $bus"
|
||||
error "This container does not support host mode networking!"
|
||||
exit 29
|
||||
fi
|
||||
|
||||
if [[ "$DHCP" == [Yy1]* ]]; then
|
||||
|
||||
checkOS
|
||||
|
||||
if [[ "${nic,,}" == "ipvlan" ]]; then
|
||||
error "This container does not support IPVLAN networking when DHCP=Y."
|
||||
exit 29
|
||||
fi
|
||||
|
||||
if [[ "${nic,,}" != "macvlan" ]]; then
|
||||
[[ "$DEBUG" == [Yy1]* ]] && info "Detected NIC: $nic"
|
||||
error "The container needs to be in a MACVLAN network when DHCP=Y."
|
||||
exit 29
|
||||
fi
|
||||
|
||||
else
|
||||
|
||||
if [[ "$IP" != "172."* && "$IP" != "10.8"* && "$IP" != "10.9"* ]]; then
|
||||
checkOS
|
||||
fi
|
||||
|
||||
fi
|
||||
|
||||
local mtu=""
|
||||
|
||||
if [ -f "/sys/class/net/$VM_NET_DEV/mtu" ]; then
|
||||
mtu=$(< "/sys/class/net/$VM_NET_DEV/mtu")
|
||||
fi
|
||||
|
||||
[ -z "$MTU" ] && MTU="$mtu"
|
||||
[ -z "$MTU" ] && MTU="0"
|
||||
|
||||
if [ "$MTU" -gt "1500" ]; then
|
||||
info "MTU size is too large: $MTU, ignoring..." && MTU="0"
|
||||
[[ "$DEBUG" == [Yy1]* ]] && echo "MTU size is too large: $MTU, ignoring..."
|
||||
MTU="0"
|
||||
fi
|
||||
|
||||
if [[ "${ADAPTER,,}" != "virtio-net-pci" ]]; then
|
||||
@@ -435,19 +662,27 @@ getInfo() {
|
||||
error "Invalid MAC address: '$VM_NET_MAC', should be 12 or 17 digits long!" && exit 28
|
||||
fi
|
||||
|
||||
GATEWAY=$(ip route list dev "$VM_NET_DEV" | awk ' /^default/ {print $3}' | head -n 1)
|
||||
IP=$(ip address show dev "$VM_NET_DEV" | grep inet | awk '/inet / { print $2 }' | cut -f1 -d/ | head -n 1)
|
||||
GATEWAY_MAC=$(echo "$VM_NET_MAC" | md5sum | sed 's/^\(..\)\(..\)\(..\)\(..\)\(..\).*$/02:\1:\2:\3:\4:\5/')
|
||||
|
||||
IP6=""
|
||||
# shellcheck disable=SC2143
|
||||
if [ -f /proc/net/if_inet6 ] && [ -n "$(ifconfig -a | grep inet6)" ]; then
|
||||
IP6=$(ip -6 addr show dev "$VM_NET_DEV" scope global up)
|
||||
[ -n "$IP6" ] && IP6=$(echo "$IP6" | sed -e's/^.*inet6 \([^ ]*\)\/.*$/\1/;t;d' | head -n 1)
|
||||
if [[ "$PODMAN" == [Yy1]* && "$DHCP" != [Yy1]* ]]; then
|
||||
if [ -z "$NETWORK" ] || [[ "${NETWORK^^}" == "Y" ]]; then
|
||||
# By default Podman has no permissions for NAT networking
|
||||
NETWORK="user"
|
||||
fi
|
||||
fi
|
||||
|
||||
[ -f "/run/.containerenv" ] && PODMAN="Y" || PODMAN="N"
|
||||
echo "$IP" > /run/shm/qemu.ip
|
||||
if [[ "$DEBUG" == [Yy1]* ]]; then
|
||||
line="Host: $HOST IP: $IP Gateway: $GATEWAY Interface: $VM_NET_DEV MAC: $VM_NET_MAC MTU: $mtu"
|
||||
[[ "$MTU" != "0" && "$MTU" != "$mtu" ]] && line+=" ($MTU)"
|
||||
info "$line"
|
||||
if [ -f /etc/resolv.conf ]; then
|
||||
nameservers=$(grep '^nameserver*' /etc/resolv.conf | head -c -1 | sed 's/nameserver //g;' | sed -z 's/\n/, /g')
|
||||
[ -n "$nameservers" ] && info "Nameservers: $nameservers"
|
||||
fi
|
||||
echo
|
||||
fi
|
||||
|
||||
echo "$IP" > /run/shm/qemu.ip
|
||||
return 0
|
||||
}
|
||||
|
||||
@@ -460,38 +695,19 @@ if [[ "$NETWORK" == [Nn]* ]]; then
|
||||
return 0
|
||||
fi
|
||||
|
||||
getInfo
|
||||
html "Initializing network..."
|
||||
msg="Initializing network..."
|
||||
html "$msg"
|
||||
[[ "$DEBUG" == [Yy1]* ]] && echo "$msg"
|
||||
|
||||
if [[ "$DEBUG" == [Yy1]* ]]; then
|
||||
mtu=$(cat "/sys/class/net/$VM_NET_DEV/mtu")
|
||||
line="Host: $HOST IP: $IP Gateway: $GATEWAY Interface: $VM_NET_DEV MAC: $VM_NET_MAC MTU: $mtu"
|
||||
[[ "$MTU" != "0" && "$MTU" != "$mtu" ]] && line+=" ($MTU)"
|
||||
info "$line"
|
||||
if [ -f /etc/resolv.conf ]; then
|
||||
nameservers=$(grep '^nameserver*' /etc/resolv.conf | head -c -1 | sed 's/nameserver //g;' | sed -z 's/\n/, /g')
|
||||
[ -n "$nameservers" ] && info "Nameservers: $nameservers"
|
||||
fi
|
||||
echo
|
||||
fi
|
||||
getInfo
|
||||
cleanUp
|
||||
|
||||
if [[ "$IP" == "172.17."* ]]; then
|
||||
warn "your container IP starts with 172.17.* which will cause conflicts when you install the Container Manager package inside DSM!"
|
||||
fi
|
||||
|
||||
if [[ -d "/sys/class/net/$VM_NET_TAP" ]]; then
|
||||
info "Lingering interface will be removed..."
|
||||
ip link delete "$VM_NET_TAP" || true
|
||||
fi
|
||||
|
||||
if [[ "$DHCP" == [Yy1]* ]]; then
|
||||
|
||||
checkOS
|
||||
|
||||
if [[ "$IP" == "172."* ]]; then
|
||||
warn "container IP starts with 172.* which is often a sign that you are not on a macvlan network (required for DHCP)!"
|
||||
fi
|
||||
|
||||
# Configure for macvtap interface
|
||||
configureDHCP || exit 20
|
||||
|
||||
@@ -500,10 +716,6 @@ if [[ "$DHCP" == [Yy1]* ]]; then
|
||||
|
||||
else
|
||||
|
||||
if [[ "$IP" != "172."* && "$IP" != "10.8"* && "$IP" != "10.9"* ]]; then
|
||||
checkOS
|
||||
fi
|
||||
|
||||
if [[ "${WEB:-}" != [Nn]* ]]; then
|
||||
|
||||
# Shutdown nginx
|
||||
@@ -512,32 +724,49 @@ else
|
||||
|
||||
fi
|
||||
|
||||
if [[ "${NETWORK,,}" != "user"* ]]; then
|
||||
case "${NETWORK,,}" in
|
||||
"user"* | "passt" | "slirp" ) ;;
|
||||
"nat" | "tap" | "tun" | "tuntap" | "y" )
|
||||
|
||||
# Configure for tap interface
|
||||
if ! configureNAT; then
|
||||
# Configure tap interface
|
||||
if ! configureNAT; then
|
||||
|
||||
closeBridge
|
||||
NETWORK="user"
|
||||
msg="falling back to user-mode networking!"
|
||||
if [[ "$PODMAN" != [Yy1]* ]]; then
|
||||
msg="an error occured, $msg"
|
||||
else
|
||||
msg="podman detected, $msg"
|
||||
closeBridge
|
||||
NETWORK="user"
|
||||
msg="falling back to user-mode networking!"
|
||||
msg="failed to setup NAT networking, $msg"
|
||||
|
||||
fi ;;
|
||||
|
||||
esac
|
||||
|
||||
[[ "${NETWORK,,}" == "user"* ]] && NETWORK="passt"
|
||||
|
||||
case "${NETWORK,,}" in
|
||||
"nat" | "tap" | "tun" | "tuntap" | "y" ) ;;
|
||||
"passt" )
|
||||
|
||||
# Configure for user-mode networking (passt)
|
||||
if ! configurePasst; then
|
||||
error "Failed to configure user-mode networking!"
|
||||
exit 24
|
||||
fi ;;
|
||||
|
||||
"slirp" )
|
||||
|
||||
# Configure for user-mode networking (slirp)
|
||||
if ! configureSlirp; then
|
||||
error "Failed to configure user-mode networking!"
|
||||
exit 24
|
||||
fi
|
||||
warn "$msg"
|
||||
[ -z "$USER_PORTS" ] && info "Notice: port mapping will not work without \"USER_PORTS\" now."
|
||||
|
||||
fi
|
||||
if [ -z "$USER_PORTS" ]; then
|
||||
info "Notice: slirp networking is active, so when you want to expose ports, you will need to map them using this variable: \"USER_PORTS=5000,5001\"."
|
||||
fi ;;
|
||||
|
||||
fi
|
||||
|
||||
if [[ "${NETWORK,,}" == "user"* ]]; then
|
||||
|
||||
# Configure for user-mode networking (slirp)
|
||||
configureUser || exit 24
|
||||
|
||||
fi
|
||||
*)
|
||||
error "Unrecognized NETWORK value: \"$NETWORK\"" && exit 24 ;;
|
||||
esac
|
||||
|
||||
fi
|
||||
|
||||
|
||||
14
src/power.sh
14
src/power.sh
@@ -1,15 +1,15 @@
|
||||
#!/usr/bin/env bash
|
||||
set -Eeuo pipefail
|
||||
|
||||
: "${API_TIMEOUT:="50"}" # API Call timeout
|
||||
: "${QEMU_TIMEOUT:="50"}" # QEMU Termination timeout
|
||||
|
||||
# Configure QEMU for graceful shutdown
|
||||
|
||||
API_CMD=6
|
||||
API_HOST="127.0.0.1:2210"
|
||||
: "${API_TIMEOUT:="50"}" # API Call timeout
|
||||
API_HOST="127.0.0.1:$COM_PORT"
|
||||
|
||||
QEMU_TERM=""
|
||||
QEMU_PORT=7100
|
||||
: "${QEMU_TIMEOUT:="50"}" # QEMU Termination timeout
|
||||
QEMU_DIR="/run/shm"
|
||||
QEMU_PID="$QEMU_DIR/qemu.pid"
|
||||
QEMU_LOG="$QEMU_DIR/qemu.log"
|
||||
@@ -83,7 +83,7 @@ terminal() {
|
||||
fi
|
||||
|
||||
if [ ! -c "$dev" ]; then
|
||||
dev=$(echo 'info chardev' | nc -q 1 -w 1 localhost "$QEMU_PORT" | tr -d '\000')
|
||||
dev=$(echo 'info chardev' | nc -q 1 -w 1 localhost "$MON_PORT" | tr -d '\000')
|
||||
dev="${dev#*serial0}"
|
||||
dev="${dev#*pty:}"
|
||||
dev="${dev%%$'\n'*}"
|
||||
@@ -127,7 +127,7 @@ _graceful_shutdown() {
|
||||
fi
|
||||
|
||||
# Don't send the powerdown signal because vDSM ignores ACPI signals
|
||||
# echo 'system_powerdown' | nc -q 1 -w 1 localhost "${QEMU_PORT}" > /dev/null
|
||||
# echo 'system_powerdown' | nc -q 1 -w 1 localhost "$MON_PORT" > /dev/null
|
||||
|
||||
# Send shutdown command to guest agent via serial port
|
||||
url="http://$API_HOST/read?command=$API_CMD&timeout=$API_TIMEOUT"
|
||||
@@ -172,7 +172,7 @@ _graceful_shutdown() {
|
||||
MON_OPTS="\
|
||||
-pidfile $QEMU_PID \
|
||||
-name $PROCESS,process=$PROCESS,debug-threads=on \
|
||||
-monitor telnet:localhost:$QEMU_PORT,server,nowait,nodelay"
|
||||
-monitor telnet:localhost:$MON_PORT,server,nowait,nodelay"
|
||||
|
||||
if [[ "$CONSOLE" != [Yy]* ]]; then
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ page="/run/shm/index.html"
|
||||
address="/run/shm/qemu.ip"
|
||||
shutdown="/run/shm/qemu.end"
|
||||
template="/var/www/index.html"
|
||||
url="http://127.0.0.1:2210/read?command=10"
|
||||
url="http://127.0.0.1:$COM_PORT/read?command=10"
|
||||
|
||||
resp_err="Guest returned an invalid response:"
|
||||
curl_err="Failed to connect to guest: curl error"
|
||||
|
||||
38
src/reset.sh
38
src/reset.sh
@@ -2,13 +2,11 @@
|
||||
set -Eeuo pipefail
|
||||
|
||||
trap 'error "Status $? while: $BASH_COMMAND (line $LINENO/$BASH_LINENO)"' ERR
|
||||
[[ "${TRACE:-}" == [Yy1]* ]] && set -o functrace && trap 'echo "# $BASH_COMMAND" >&2' DEBUG
|
||||
|
||||
[ ! -f "/run/entry.sh" ] && error "Script must run inside Docker container!" && exit 11
|
||||
[ ! -f "/run/entry.sh" ] && error "Script must be run inside the container!" && exit 11
|
||||
[ "$(id -u)" -ne "0" ] && error "Script must be executed with root privileges." && exit 12
|
||||
|
||||
echo "❯ Starting $APP for Docker v$(</run/version)..."
|
||||
echo "❯ For support visit $SUPPORT"
|
||||
|
||||
# Docker environment variables
|
||||
|
||||
: "${TZ:=""}" # System local timezone
|
||||
@@ -25,13 +23,23 @@ echo "❯ For support visit $SUPPORT"
|
||||
|
||||
# Helper variables
|
||||
|
||||
PODMAN="N"
|
||||
ENGINE="Docker"
|
||||
PROCESS="${APP,,}"
|
||||
PROCESS="${PROCESS// /-}"
|
||||
|
||||
if [ -f "/run/.containerenv" ]; then
|
||||
PODMAN="Y"
|
||||
ENGINE="Podman"
|
||||
fi
|
||||
|
||||
echo "❯ Starting $APP for $ENGINE v$(</run/version)..."
|
||||
echo "❯ For support visit $SUPPORT"
|
||||
|
||||
INFO="/run/shm/msg.html"
|
||||
PAGE="/run/shm/index.html"
|
||||
TEMPLATE="/var/www/index.html"
|
||||
FOOTER1="$APP for Docker v$(</run/version)"
|
||||
FOOTER1="$APP for $ENGINE v$(</run/version)"
|
||||
FOOTER2="<a href='$SUPPORT'>$SUPPORT</a>"
|
||||
|
||||
CPU=$(cpu)
|
||||
@@ -202,19 +210,25 @@ addPackage() {
|
||||
return 0
|
||||
}
|
||||
|
||||
: "${COM_PORT:="2210"}" # Comm port
|
||||
: "${MON_PORT:="7100"}" # Monitor port
|
||||
: "${WEB_PORT:="5000"}" # Webserver port
|
||||
: "${CHR_PORT:="12345"}" # Character port
|
||||
|
||||
cp -r /var/www/* /run/shm
|
||||
html "Starting $APP for Docker..."
|
||||
html "Starting $APP for $ENGINE..."
|
||||
|
||||
if [[ "${WEB:-}" != [Nn]* ]]; then
|
||||
|
||||
|
||||
mkdir -p /etc/nginx/sites-enabled
|
||||
cp /etc/nginx/default.conf /etc/nginx/sites-enabled/web.conf
|
||||
|
||||
sed -i "s/listen 5000 default_server;/listen $WEB_PORT default_server;/g" /etc/nginx/sites-enabled/web.conf
|
||||
|
||||
# shellcheck disable=SC2143
|
||||
if [ -f /proc/net/if_inet6 ] && [ -n "$(ifconfig -a | grep inet6)" ]; then
|
||||
|
||||
sed -i "s/listen 5000 default_server;/listen [::]:5000 default_server ipv6only=off;/g" /etc/nginx/sites-enabled/web.conf
|
||||
|
||||
else
|
||||
|
||||
sed -i "s/listen [::]:5000 default_server ipv6only=off;/listen 5000 default_server;/g" /etc/nginx/sites-enabled/web.conf
|
||||
sed -i "s/listen $WEB_PORT default_server;/listen [::]:$WEB_PORT default_server ipv6only=off;/g" /etc/nginx/sites-enabled/web.conf
|
||||
|
||||
fi
|
||||
|
||||
|
||||
@@ -45,7 +45,7 @@ fi
|
||||
cnt=0
|
||||
sleep 0.2
|
||||
|
||||
while ! nc -z -w2 127.0.0.1 2210 > /dev/null 2>&1; do
|
||||
while ! nc -z -w2 127.0.0.1 "$COM_PORT" > /dev/null 2>&1; do
|
||||
sleep 0.1
|
||||
cnt=$((cnt + 1))
|
||||
(( cnt > 50 )) && error "Failed to connect to qemu-host.." && exit 58
|
||||
@@ -53,7 +53,7 @@ done
|
||||
|
||||
cnt=0
|
||||
|
||||
while ! nc -z -w2 127.0.0.1 12345 > /dev/null 2>&1; do
|
||||
while ! nc -z -w2 127.0.0.1 "$CHR_PORT" > /dev/null 2>&1; do
|
||||
sleep 0.1
|
||||
cnt=$((cnt + 1))
|
||||
(( cnt > 50 )) && error "Failed to connect to qemu-host.." && exit 59
|
||||
@@ -69,7 +69,7 @@ fi
|
||||
|
||||
SERIAL_OPTS+=" \
|
||||
-device virtio-serial-pci,id=virtio-serial0,bus=pcie.0,addr=0x3 \
|
||||
-chardev socket,id=charchannel0,host=127.0.0.1,port=12345,reconnect=10 \
|
||||
-chardev socket,id=charchannel0,host=127.0.0.1,port=$CHR_PORT,reconnect=10 \
|
||||
-device virtserialport,bus=virtio-serial0.0,nr=1,chardev=charchannel0,id=channel0,name=vchannel"
|
||||
|
||||
return 0
|
||||
|
||||
4
src/start.sh
Normal file
4
src/start.sh
Normal file
@@ -0,0 +1,4 @@
|
||||
#!/usr/bin/env bash
|
||||
set -Eeuo pipefail
|
||||
|
||||
# Override this placeholder file using a Docker bind to execute a script during startup!
|
||||
@@ -126,8 +126,8 @@ cpu() {
|
||||
cpu="${cpu// [0-9] Core}"
|
||||
cpu="${cpu// [0-9][0-9] Core}"
|
||||
cpu="${cpu// [0-9][0-9][0-9] Core}"
|
||||
cpu="${cpu// [0-9]th Gen}"
|
||||
cpu="${cpu// [0-9][0-9]th Gen}"
|
||||
cpu="${cpu//[0-9]th Gen }"
|
||||
cpu="${cpu//[0-9][0-9]th Gen }"
|
||||
cpu="${cpu// Processor/}"
|
||||
cpu="${cpu// Quad core/}"
|
||||
cpu="${cpu// Dual core/}"
|
||||
|
||||
Reference in New Issue
Block a user