-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup_worker.sh
More file actions
executable file
·103 lines (83 loc) · 2.98 KB
/
setup_worker.sh
File metadata and controls
executable file
·103 lines (83 loc) · 2.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/bin/bash
set -e # Exit on error
AOSP_DIR="$1"
if [[ -z "$AOSP_DIR" ]]; then
echo "Usage: $0 <aosp_directory>"
exit 1
fi
AOSP_DIR=$(realpath "$AOSP_DIR")
# Prompt for master IP if not set
read -p "Enter master IP address: " MASTER_IP
if [[ -z "$MASTER_IP" ]]; then
echo "Master IP required."
exit 1
fi
# Install dependencies
echo "Installing distcc and dependencies..."
sudo apt update
sudo apt install -y distcc rsync openssh-server
# Auto-detect cores
CORES=$(nproc --all)
JOBS=$((CORES * 2)) # Conservative overcommit
# Ensure distcc user exists
sudo useradd -r -s /bin/false distcc 2>/dev/null || true
# Always create/update systemd service for distccd
echo "Creating/updating distccd systemd service..."
sudo tee /etc/systemd/system/distccd.service > /dev/null <<EOF
[Unit]
Description=distcc distributed compiler daemon
After=network.target
[Service]
Type=forking
ExecStart=/usr/bin/distccd --daemon --allow $MASTER_IP --jobs ${JOBS} --log-level info --verbose
User=distcc
Group=distcc
[Install]
WantedBy=multi-user.target
EOF
sudo systemctl daemon-reload
# Configure distccd
echo "Configuring distccd to allow $MASTER_IP, jobs: $JOBS"
# Add network range to allowed networks (allows master and its subnet)
if [[ $MASTER_IP =~ ^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
# Convert IP to /24 subnet
ALLOWED_NETS="$MASTER_IP/24"
else
ALLOWED_NETS="$MASTER_IP"
fi
sudo sed -i 's#^ALLOWEDNETS=.*#ALLOWEDNETS="'"$ALLOWED_NETS"'"#' /etc/default/distcc
sudo sed -i 's/^MAX_JOBS=.*/MAX_JOBS='"$JOBS"'/' /etc/default/distcc
# Configure firewall to allow distcc connections
echo "Configuring firewall for distcc..."
if command -v ufw >/dev/null 2>&1; then
sudo ufw allow from $MASTER_IP to any port 3632 proto tcp
elif command -v iptables >/dev/null 2>&1; then
sudo iptables -A INPUT -p tcp -s $MASTER_IP --dport 3632 -j ACCEPT
sudo iptables-save | sudo tee /etc/iptables/rules.v4 >/dev/null 2>&1 || true
fi
# Start and enable distccd
echo "Starting distccd service..."
sudo systemctl enable distccd
sudo systemctl restart distccd
# Wait a moment and check status
sleep 2
if sudo systemctl is-active --quiet distccd; then
echo "distccd started successfully with $JOBS jobs."
else
echo "Warning: distccd failed to start. Checking logs..."
# Try to show recent logs without requiring sudo
if command -v journalctl >/dev/null 2>&1; then
echo "Recent distccd logs:"
echo "----------------------------------------"
sudo journalctl -u distccd --no-pager -n 10 | tail -n 20 || echo "Cannot read logs (permission denied)"
echo "----------------------------------------"
fi
echo "You may need to manually troubleshoot with: sudo journalctl -u distccd -f"
fi
echo "distccd status: $(systemctl is-active distccd 2>/dev/null || echo 'unknown')"
# Create AOSP dir if missing
mkdir -p "$AOSP_DIR"
echo "Worker setup complete for $AOSP_DIR."
if [[ ! -d "$AOSP_DIR/build/soong" ]]; then
echo "Warning: $AOSP_DIR does not look like an AOSP root (missing build/soong), probably was not synced yet"
fi