Skip to content

Commit 72938db

Browse files
committed
feat: Add systemd socket proxy for backward compatibility
Instead of symlinks (which don't work with Docker bind mounts because Docker resolves them to the target file's inode), use systemd socket activation with systemd-socket-proxyd. Key insight: systemd.socket creates and owns the socket file, not the service process. This means: - The socket file persists across proxy service restarts - The inode never changes - Containers that mount /var/run/dstack.sock directly will continue to work even after guest-agent restarts Added: - dstack-socket-compat.socket + .service: /var/run/dstack.sock proxy - tappd-socket-compat.socket + .service: /var/run/tappd.sock proxy Removed: - Symlink creation in system_setup.rs (ineffective for this purpose)
1 parent 163cf4c commit 72938db

7 files changed

Lines changed: 66 additions & 10 deletions

File tree

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# SPDX-FileCopyrightText: 2024-2025 Phala Network <dstack@phala.network>
2+
#
3+
# SPDX-License-Identifier: Apache-2.0
4+
5+
# Proxy service that forwards connections from /var/run/dstack.sock to /var/run/dstack/dstack.sock.
6+
# Used for backward compatibility with containers that mount the socket file directly.
7+
8+
[Unit]
9+
Description=dstack socket proxy for backward compatibility
10+
Requires=dstack-socket-compat.socket
11+
After=dstack-guest-agent.service
12+
13+
[Service]
14+
ExecStart=/usr/lib/systemd/systemd-socket-proxyd /var/run/dstack/dstack.sock
15+
Type=notify
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# SPDX-FileCopyrightText: 2024-2025 Phala Network <dstack@phala.network>
2+
#
3+
# SPDX-License-Identifier: Apache-2.0
4+
5+
# Backward compatibility socket for containers that mount /var/run/dstack.sock directly.
6+
# The socket is owned by systemd, so it survives service restarts without inode changes.
7+
8+
[Unit]
9+
Description=dstack backward compatibility socket (dstack.sock)
10+
11+
[Socket]
12+
ListenStream=/var/run/dstack.sock
13+
SocketMode=0777
14+
15+
[Install]
16+
WantedBy=sockets.target
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# SPDX-FileCopyrightText: 2024-2025 Phala Network <dstack@phala.network>
2+
#
3+
# SPDX-License-Identifier: Apache-2.0
4+
5+
# Proxy service that forwards connections from /var/run/tappd.sock to /var/run/dstack/tappd.sock.
6+
# Used for backward compatibility with containers that mount the socket file directly.
7+
8+
[Unit]
9+
Description=tappd socket proxy for backward compatibility
10+
Requires=tappd-socket-compat.socket
11+
After=dstack-guest-agent.service
12+
13+
[Service]
14+
ExecStart=/usr/lib/systemd/systemd-socket-proxyd /var/run/dstack/tappd.sock
15+
Type=notify
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# SPDX-FileCopyrightText: 2024-2025 Phala Network <dstack@phala.network>
2+
#
3+
# SPDX-License-Identifier: Apache-2.0
4+
5+
# Backward compatibility socket for containers that mount /var/run/tappd.sock directly.
6+
# The socket is owned by systemd, so it survives service restarts without inode changes.
7+
8+
[Unit]
9+
Description=dstack backward compatibility socket (tappd.sock)
10+
11+
[Socket]
12+
ListenStream=/var/run/tappd.sock
13+
SocketMode=0777
14+
15+
[Install]
16+
WantedBy=sockets.target

dstack-util/src/system_setup.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1465,17 +1465,11 @@ impl Stage1<'_> {
14651465
Ok(())
14661466
}
14671467

1468-
/// Setup socket directory and backward compatibility symlinks.
1469-
/// Creates /var/run/dstack/ directory and symlinks for old socket paths.
1468+
/// Setup socket directory for dstack-guest-agent.
14701469
fn setup_socket_dir(&self) -> Result<()> {
1471-
info!("Setting up socket directory and backward compatibility symlinks");
1470+
info!("Setting up socket directory");
14721471
cmd! {
1473-
// Create the new socket directory
14741472
mkdir -p /var/run/dstack;
1475-
// Create backward compatibility symlinks (old path -> new path)
1476-
// These allow old containers that mount the file directly to still work
1477-
ln -sf /var/run/dstack/dstack.sock /var/run/dstack.sock;
1478-
ln -sf /var/run/dstack/tappd.sock /var/run/tappd.sock;
14791473
}?;
14801474
Ok(())
14811475
}

sdk/curl/api-tappd.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ services:
1616
- /var/run/dstack:/var/run/dstack
1717
```
1818
19-
> **Note:** The old path `/var/run/tappd.sock` is still supported via symlink for backward compatibility.
19+
> **Note:** The old path `/var/run/tappd.sock` is still supported via systemd socket proxy for backward compatibility.
2020

2121
## Endpoints
2222

sdk/curl/api.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ services:
1616
- /var/run/dstack:/var/run/dstack
1717
```
1818
19-
> **Note:** The old path `/var/run/dstack.sock` is still supported via symlink for backward compatibility.
19+
> **Note:** The old path `/var/run/dstack.sock` is still supported via systemd socket proxy for backward compatibility.
2020

2121
## Endpoints
2222

0 commit comments

Comments
 (0)