Skip to content

Commit 7fee40c

Browse files
committed
hostrun -> host_run
1 parent e22ae2c commit 7fee40c

File tree

3 files changed

+66
-80
lines changed

3 files changed

+66
-80
lines changed

README.md

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,6 @@
22

33
A Docker-based installer for [Sysbox](https://github.com/nestybox/sysbox) on read-only dstack systems.
44

5-
## Features
6-
7-
- 🚀 **Single-command installation** - One Docker run command installs everything
8-
- 🔒 **Source-built** - Builds Sysbox from verified Git source (v0.6.7)
9-
-**SHA256 verified** - All downloads verified with checksums
10-
- 🔄 **Smart overlay handling** - Preserves existing /etc configurations
11-
- 📋 **Systemd integration** - Installs proper systemd services for Sysbox daemons
12-
- 🔍 **Installation detection** - Checks for existing installations
13-
- 🧪 **Built-in testing** - Verifies installation with basic and Docker-in-Docker tests
14-
155
## Quick Start
166

177
### Build the Installer
@@ -24,7 +14,7 @@ chmod +x build.sh
2414

2515
### Install Sysbox
2616

27-
**Single command installation:**
17+
**Single command installation in a CVM:**
2818
```bash
2919
docker run --rm --privileged --pid=host --net=host -v /:/host \
3020
sysbox-installer:latest
@@ -33,9 +23,9 @@ docker run --rm --privileged --pid=host --net=host -v /:/host \
3323
That's it! The installer will:
3424
- Check for existing installations
3525
- Build and install Sysbox from source
36-
- Handle /etc overlay mount complexities
37-
- Configure Docker runtime
38-
- Create and start systemd services
26+
- Handle /etc volatile overlay mount preserving configs
27+
- Configure Docker runtime using Sysbox's official script
28+
- Create transient systemd services and start daemons
3929

4030
## Manual Steps (if needed)
4131

@@ -101,14 +91,13 @@ installer/
10191

10292
### What the Installer Does
10393

104-
1. **Checks existing installation** - Prompts before overwriting
94+
1. **Checks existing installation** - Detects and reports existing Sysbox installations
10595
2. **Copies binaries** - Places Sysbox binaries in `/usr/bin` (writable location)
106-
3. **Sets up /etc overlay** - Creates persistent overlay preserving existing configs
107-
4. **Creates symlinks** - Links rsync, modprobe, iptables for Sysbox requirements
108-
5. **Configures Docker** - Adds sysbox-runc runtime to Docker daemon
109-
6. **Creates systemd services** - Installs proper service files with dependencies
110-
7. **Starts services** - Enables and starts Sysbox daemons
111-
8. **Tests installation** - Verifies basic and Docker-in-Docker functionality
96+
3. **Sets up /etc overlay** - Creates volatile overlay preserving existing configs (WireGuard, Docker)
97+
4. **Creates symlinks** - Links fusermount, modprobe, iptables for Sysbox requirements
98+
5. **Configures Docker** - Uses Sysbox's official docker-cfg script to properly merge runtime configuration
99+
6. **Creates systemd services** - Installs transient service files in `/run/systemd/system`
100+
7. **Starts services** - Starts Sysbox manager and filesystem daemons
112101

113102
### Data Locations
114103

@@ -144,8 +133,9 @@ docker run --runtime=sysbox-runc --rm alpine echo "Test successful"
144133
```bash
145134
systemctl stop sysbox-mgr sysbox-fs
146135
systemctl disable sysbox-mgr sysbox-fs
147-
rm -f /etc/systemd/system/sysbox-*.service
148-
umount /etc # If overlay mounted
136+
rm -f /run/systemd/system/sysbox-*.service
137+
systemctl daemon-reload
138+
umount /etc # If volatile overlay mounted
149139
rm -rf /dstack/persistent/sysbox-*
150140
```
151141

docker/Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ COPY --from=builder /build/rsync-3.2.7/rsync /usr/local/bin/rsync
6666
COPY --from=builder /build/sysbox-install/sysbox-runc /usr/local/bin/sysbox-runc
6767
COPY --from=builder /build/sysbox-install/sysbox-mgr /usr/local/bin/sysbox-mgr
6868
COPY --from=builder /build/sysbox-install/sysbox-fs /usr/local/bin/sysbox-fs
69+
COPY --from=builder /build/sysbox/scr/docker-cfg /usr/local/bin/sysbox-docker-cfg
6970

7071
# Copy scripts and service files
7172
COPY scripts/install-sysbox-complete.sh /usr/local/bin/install-sysbox-complete.sh

scripts/install-sysbox-complete.sh

Lines changed: 52 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ log_error() {
3030
}
3131

3232
# Helper function to run commands on host via nsenter
33-
hostrun() {
33+
host_run() {
3434
nsenter -t 1 -m -p -n "$@"
3535
}
3636

@@ -39,18 +39,18 @@ check_existing() {
3939
log_info "Checking existing installation..."
4040

4141
# Check if systemd services exist (in either /etc or /run)
42-
if hostrun systemctl list-unit-files | grep -q "sysbox-mgr.service" ||
42+
if host_run systemctl list-unit-files | grep -q "sysbox-mgr.service" ||
4343
[ -f /host/run/systemd/system/sysbox-mgr.service ] ||
4444
[ -f /host/etc/systemd/system/sysbox-mgr.service ]; then
4545
log_warning "Sysbox services already installed - skipping installation"
4646

4747
# Show service status
4848
echo "Service status:"
49-
hostrun systemctl status sysbox-mgr.service --no-pager 2>/dev/null | head -5 || true
50-
hostrun systemctl status sysbox-fs.service --no-pager 2>/dev/null | head -5 || true
49+
host_run systemctl status sysbox-mgr.service --no-pager 2>/dev/null | head -5 || true
50+
host_run systemctl status sysbox-fs.service --no-pager 2>/dev/null | head -5 || true
5151

5252
# Check if actually running
53-
if hostrun systemctl is-active sysbox-mgr.service >/dev/null 2>&1; then
53+
if host_run systemctl is-active sysbox-mgr.service >/dev/null 2>&1; then
5454
log_success "Sysbox is installed and running"
5555
else
5656
log_info "Sysbox is installed but not running. Start with:"
@@ -76,14 +76,14 @@ copy_binaries() {
7676
chmod +x /host/usr/bin/rsync /host/usr/bin/sysbox-*
7777

7878
# Create symlinks for dependencies
79-
hostrun ln -sf /usr/sbin/modprobe /usr/bin/modprobe 2>/dev/null || true
80-
hostrun ln -sf /usr/sbin/iptables /usr/bin/iptables 2>/dev/null || true
79+
host_run ln -sf /usr/sbin/modprobe /usr/bin/modprobe 2>/dev/null || true
80+
host_run ln -sf /usr/sbin/iptables /usr/bin/iptables 2>/dev/null || true
8181

8282
# Handle fusermount/fusermount3 (Alpine has fusermount3, sysbox expects fusermount)
83-
if ! hostrun which fusermount >/dev/null 2>&1; then
84-
if hostrun which fusermount3 >/dev/null 2>&1; then
83+
if ! host_run which fusermount >/dev/null 2>&1; then
84+
if host_run which fusermount3 >/dev/null 2>&1; then
8585
log_info "Creating symlink: fusermount -> fusermount3"
86-
hostrun ln -sf /usr/bin/fusermount3 /usr/bin/fusermount
86+
host_run ln -sf /usr/bin/fusermount3 /usr/bin/fusermount
8787
else
8888
log_warning "Neither fusermount nor fusermount3 found - FUSE operations may fail"
8989
fi
@@ -94,54 +94,54 @@ copy_binaries() {
9494

9595
setup_subuid_subgid() {
9696
log_info "Setting up subuid/subgid..."
97-
hostrun sh -c 'echo "sysbox:200000:65536" > /etc/subuid'
98-
hostrun sh -c 'echo "sysbox:200000:65536" > /etc/subgid'
97+
host_run sh -c 'echo "sysbox:200000:65536" > /etc/subuid'
98+
host_run sh -c 'echo "sysbox:200000:65536" > /etc/subgid'
9999
log_success "Created subuid/subgid mappings"
100100
}
101101

102102
# Setup /etc overlay and configuration
103103
setup_etc_overlay() {
104104
# Check if main overlay already exists
105-
if hostrun mount | grep -q " /etc .*overlay"; then
105+
if host_run mount | grep -q " /etc .*overlay"; then
106106
log_warning "/etc already has overlay mounted - skipping mount"
107107
return
108108
fi
109109

110110
log_info "Setting up /etc overlay..."
111111

112112
# Create volatile overlay directories for /etc
113-
hostrun mkdir -p /var/volatile/overlay/etc/sysbox/upper /var/volatile/overlay/etc/sysbox/work
113+
host_run mkdir -p /var/volatile/overlay/etc/sysbox/upper /var/volatile/overlay/etc/sysbox/work
114114

115115
# Preserve wireguard config if it exists in volatile storage
116-
if [ -f /host/var/volatile/overlay/etc/wireguard/upper/wg0.conf ]; then
116+
if host_run [ -f /var/volatile/overlay/etc/wireguard/upper/wg0.conf ]; then
117117
log_info "Preserving existing wireguard configuration..."
118-
mkdir -p /host/var/volatile/overlay/etc/sysbox/upper/wireguard
119-
cp /host/var/volatile/overlay/etc/wireguard/upper/* /host/var/volatile/overlay/etc/sysbox/upper/wireguard/ 2>/dev/null || true
118+
host_run mkdir -p /var/volatile/overlay/etc/sysbox/upper/wireguard
119+
host_run bash -c 'cp /var/volatile/overlay/etc/wireguard/upper/* /var/volatile/overlay/etc/sysbox/upper/wireguard/ 2>/dev/null' || true
120120
fi
121121

122122
# Preserve docker config if it exists in volatile storage
123-
if [ -d /host/var/volatile/overlay/etc/docker/upper ]; then
123+
if host_run [ -d /var/volatile/overlay/etc/docker/upper/daemon.json ]; then
124124
log_info "Preserving existing Docker configuration..."
125-
mkdir -p /host/var/volatile/overlay/etc/sysbox/upper/docker
126-
cp -r /host/var/volatile/overlay/etc/docker/upper/* /host/var/volatile/overlay/etc/sysbox/upper/docker/ 2>/dev/null || true
125+
host_run mkdir -p /var/volatile/overlay/etc/sysbox/upper/docker
126+
host_run bash -c 'cp -r /var/volatile/overlay/etc/docker/upper/* /var/volatile/overlay/etc/sysbox/upper/docker/ 2>/dev/null' || true
127127
fi
128128

129129
# Unmount existing individual overlays (except /etc/users which should remain persistent)
130130
log_info "Unmounting individual overlays..."
131-
hostrun umount /etc/wireguard 2>/dev/null || true
132-
hostrun umount /etc/docker 2>/dev/null || true
131+
host_run umount /etc/wireguard 2>/dev/null || true
132+
host_run umount /etc/docker 2>/dev/null || true
133133

134134
# Mount volatile /etc overlay
135-
hostrun mount -t overlay overlay \
135+
host_run mount -t overlay overlay \
136136
-o lowerdir=/etc,upperdir=/var/volatile/overlay/etc/sysbox/upper,workdir=/var/volatile/overlay/etc/sysbox/work \
137137
/etc
138138
log_success "Volatile /etc overlay mounted"
139139

140140
# Remount /etc/users as persistent (if it exists) to override the volatile /etc mount
141-
if [ -d /host/dstack/persistent/overlay/etc/users ]; then
141+
if host_run [ -d /dstack/persistent/overlay/etc/users ]; then
142142
log_info "Remounting /etc/users as persistent overlay..."
143-
hostrun mkdir -p /dstack/persistent/overlay/etc/users/upper /dstack/persistent/overlay/etc/users/work
144-
hostrun mount -t overlay overlay \
143+
host_run mkdir -p /dstack/persistent/overlay/etc/users/upper /dstack/persistent/overlay/etc/users/work
144+
host_run mount -t overlay overlay \
145145
-o lowerdir=/etc/users,upperdir=/dstack/persistent/overlay/etc/users/upper,workdir=/dstack/persistent/overlay/etc/users/work \
146146
/etc/users
147147
log_success "/etc/users mounted as persistent overlay"
@@ -150,41 +150,36 @@ setup_etc_overlay() {
150150

151151
# Configure Docker runtime
152152
configure_docker() {
153-
log_info "Configuring Docker runtime..."
154-
155-
# TODO: Implement proper JSON merging to preserve existing Docker configuration
156-
# Currently overwrites daemon.json - should merge with existing runtimes/settings
153+
log_info "Configuring Docker runtime using Sysbox's docker-cfg script..."
157154

158155
# Backup existing daemon.json if it exists
159-
if hostrun [ -f /etc/docker/daemon.json ]; then
160-
hostrun cp /etc/docker/daemon.json /etc/docker/daemon.json.backup
161-
log_info "Backed up existing Docker daemon.json (will be overwritten)"
156+
if host_run [ -f /etc/docker/daemon.json ]; then
157+
host_run cp /etc/docker/daemon.json /etc/docker/daemon.json.backup
158+
log_info "Backed up existing Docker daemon.json"
162159
fi
163160

164-
hostrun tee /etc/docker/daemon.json >/dev/null <<'DOCKEREOF'
165-
{
166-
"log-driver": "json-file",
167-
"log-opts": {
168-
"max-size": "100m",
169-
"max-file": "10"
170-
},
171-
"runtimes": {
172-
"sysbox-runc": {
173-
"path": "/usr/bin/sysbox-runc"
174-
}
175-
}
176-
}
177-
DOCKEREOF
161+
# Use Sysbox's official docker-cfg script to configure Docker
162+
cp /usr/local/bin/sysbox-docker-cfg /usr/bin/
163+
if host_run bash /usr/bin/sysbox-docker-cfg --sysbox-runtime=enable; then
164+
log_success "Docker configuration updated with Sysbox runtime"
165+
else
166+
log_error "Failed to configure Docker with docker-cfg script"
167+
if host_run [ -f /etc/docker/daemon.json.backup ]; then
168+
host_run mv /etc/docker/daemon.json.backup /etc/docker/daemon.json
169+
log_info "Restored backup Docker configuration"
170+
fi
171+
return 1
172+
fi
178173

179-
log_success "Docker configuration updated"
174+
log_success "Docker configuration completed"
180175
}
181176

182177
# Create systemd services
183178
create_systemd_services() {
184179
log_info "Creating systemd services..."
185180

186181
# Use /run/systemd/system for runtime units (doesn't require persistent storage)
187-
hostrun mkdir -p /run/systemd/system
182+
host_run mkdir -p /run/systemd/system
188183

189184
# Copy service files from container to host runtime directory
190185
cp /usr/local/share/sysbox-mgr.service /host/run/systemd/system/
@@ -204,7 +199,7 @@ create_systemd_services() {
204199
log_success "Service files copied to /run/systemd/system/"
205200

206201
# Reload systemd to pick up new service files
207-
hostrun systemctl daemon-reload
202+
host_run systemctl daemon-reload
208203

209204
log_success "Systemd services created (transient until reboot)"
210205
log_info "Services: sysbox-mgr, sysbox-fs"
@@ -215,20 +210,20 @@ start_sysbox() {
215210
log_info "Starting Sysbox services..."
216211

217212
# Create data directory
218-
hostrun mkdir -p /dstack/persistent/sysbox-data
213+
host_run mkdir -p /dstack/persistent/sysbox-data
219214

220215
# Start services in order
221216
log_info "Starting Sysbox manager..."
222-
hostrun systemctl start sysbox-mgr.service
217+
host_run systemctl start sysbox-mgr.service
223218
sleep 3
224219

225220
log_info "Starting Sysbox filesystem..."
226-
hostrun systemctl start sysbox-fs.service
221+
host_run systemctl start sysbox-fs.service
227222
sleep 2
228223

229224
# Verify services are running
230-
if hostrun systemctl is-active sysbox-mgr.service >/dev/null &&
231-
hostrun systemctl is-active sysbox-fs.service >/dev/null; then
225+
if host_run systemctl is-active sysbox-mgr.service >/dev/null &&
226+
host_run systemctl is-active sysbox-fs.service >/dev/null; then
232227
log_success "Sysbox services started successfully"
233228
else
234229
log_warning "Some services may not have started correctly"
@@ -245,8 +240,8 @@ show_status() {
245240
echo "=========================================="
246241
echo
247242
echo "📊 Status:"
248-
echo " • Sysbox Manager: $(hostrun systemctl is-active sysbox-mgr.service)"
249-
echo " • Sysbox FS: $(hostrun systemctl is-active sysbox-fs.service)"
243+
echo " • Sysbox Manager: $(host_run systemctl is-active sysbox-mgr.service)"
244+
echo " • Sysbox FS: $(host_run systemctl is-active sysbox-fs.service)"
250245
echo " • Docker Runtime: Configured (restart required)"
251246
echo
252247
echo -e "${YELLOW}⚠️ IMPORTANT: Restart Docker to enable sysbox-runc runtime:${NC}"

0 commit comments

Comments
 (0)