could you guide me step by step to selfhost in VM ...
# ask-ai
b
could you guide me step by step to selfhost in VM with testing command too from strach
t
Thanks for reaching out, Vishnu. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Thanks — I can walk you through a complete, step‑by‑step VM self‑host and testing flow. Quick clarification first so I give the exact commands you need: Which LiveKit component do you want to self‑host on the VM? • LiveKit Server (core WebRTC SFU) — most common • Egress Service (recording/export) • Ingress Service (RTMP/WHIP ingest) • SIP Server (telephony) Also tell me: 1. Your VM OS (Ubuntu/Debian/CentOS/etc.) 2. Do you have a domain and DNS control for a subdomain (e.g., livekit.example.com)? 3. Do you prefer cloud‑init (automatic) or a manual install via SSH and an init script? Reply with those answers and I’ll provide a tailored, ordered checklist with exact commands and test steps. Sources: Deploy to a VM | LiveKit docs | Self-hosting the Egress Service | LiveKit docs | Self-hosting the Ingress Service | LiveKit docs | Self-hosted SIP server | LiveKit docs | livekit/livekit_composite | DeepWiki
b
• i want all of this LiveKit Server (core WebRTC SFU) — most common • Egress Service (recording/export) • Ingress Service (RTMP/WHIP ingest) • SIP Server (telephony) my Vm is ubuntu Im only having VM IP address and a manual install via SSH and an init script
t
Great — I’ll give you a concise, ordered manual install script and exact commands to deploy all four components (LiveKit Server, Egress, Ingress, SIP) on your Ubuntu VM IP-only (no domain), plus quick test commands. Paste and run the script on your VM (or run step-by-step sections manually). Replace the two placeholders below before running: • YOUR_API_KEY — choose a value (e.g., devkey) • YOUR_API_SECRET — choose a value (e.g., secret) Save this file on the VM as
setup-livekit.sh
, make it executable, then run it. Script (paste into the VM):
Copy code
#!/bin/bash
set -euo pipefail
# Usage: edit YOUR_API_KEY and YOUR_API_SECRET below, then: sudo bash setup-livekit.sh

API_KEY="YOUR_API_KEY"
API_SECRET="YOUR_API_SECRET"
VM_IP=$(curl -s ifconfig.me || hostname -I | awk '{print $1}')
WORKDIR="/opt/livekit"
mkdir -p ${WORKDIR}
cd ${WORKDIR}

# 1) Update & deps
sudo apt update && sudo apt install -y docker.io docker-compose wget curl jq ca-certificates
sudo systemctl enable --now docker
sudo usermod -aG docker $USER || true

# 2) Start Redis (Docker)
docker run -d --name livekit-redis --restart always -p 6379:6379 redis:alpine

# 3) Write LiveKit server config
cat > ${WORKDIR}/livekit.yaml <<EOF
port: 7880
rtc:
  tcp_port: 7881
  udp_port: 7882
  port_range_start: 50000
  port_range_end: 60000
  use_external_ip: true
  external_ip: ${VM_IP}
redis:
  address: ${VM_IP}:6379
keys:
  ${API_KEY}: ${API_SECRET}
logging:
  level: info
EOF

# 4) Run LiveKit Server (Docker)
docker run -d --name livekit-server --network host --restart always \
  -v ${WORKDIR}/livekit.yaml:/etc/livekit/livekit.yaml \
  livekit/livekit-server --config /etc/livekit/livekit.yaml

# 5) Egress config & run (requires chrome/gstreamer later if you need complex composites)
cat > ${WORKDIR}/egress.yaml <<EOF
api_key: ${API_KEY}
api_secret: ${API_SECRET}
ws_url: ws://${VM_IP}:7880
redis:
  address: ${VM_IP}:6379
enable_chrome_sandbox: false
prometheus_port: 7981
log_level: debug
EOF

docker run -d --name livekit-egress --cap-add SYS_ADMIN --network host --restart always \
  -v ${WORKDIR}/egress.yaml:/etc/egress/config.yaml \
  livekit/egress --config /etc/egress/config.yaml

# 6) Ingress config & run (RTMP/WHIP)
cat > ${WORKDIR}/ingress.yaml <<EOF
api_key: ${API_KEY}
api_secret: ${API_SECRET}
ws_url: ws://${VM_IP}:7880
redis:
  address: ${VM_IP}:6379
rtmp_port: 1935
whip_port: 8080
http_relay_port: 9090
rtc_config:
  tcp_port: 7885
  udp_port: 7885
  use_external_ip: true
  external_ip: ${VM_IP}
health_port: 7982
log_level: debug
EOF

docker run -d --name livekit-ingress --network host --restart always \
  -v ${WORKDIR}/ingress.yaml:/etc/ingress/config.yaml \
  livekit/ingress --config /etc/ingress/config.yaml

# 7) SIP config & run
cat > ${WORKDIR}/sip.yaml <<EOF
api_key: ${API_KEY}
api_secret: ${API_SECRET}
ws_url: ws://${VM_IP}:7880
redis:
  address: ${VM_IP}:6379
sip_port: 5060
rtp_port: 10000-20000
use_external_ip: true
external_ip: ${VM_IP}
logging:
  level: debug
EOF

docker run -d --name livekit-sip --network host --restart always \
  -v ${WORKDIR}/sip.yaml:/etc/sip/config.yaml \
  livekit/sip --config /etc/sip/config.yaml

# 8) Basic firewall suggestions (optional; may require cloud provider security group)
echo "Open these ports on your VM/network: TCP 22,7880,7881,1935,8080,9090,5060; UDP 3478,50000-60000,10000-20000"
echo "Setup complete. VM IP: ${VM_IP}"
After running the script, use these commands to verify services and perform basic tests. Service checks 1. Check container status:
Copy code
docker ps --format "table {{.Names}}\t{{.Status}}\t{{.Image}}"
1. Check logs (replace <name>):
Copy code
docker logs -f livekit-server
docker logs -f livekit-egress
docker logs -f livekit-ingress
docker logs -f livekit-sip
Quick tests 1. Generate a token (install livekit-cli or use the helper below). For a quick token with the `livekit-cli`:
Copy code
# install CLI (one-line)
curl -sSL https://get.livekit.io | bash

export LIVEKIT_URL="http://${VM_IP}:7880"
export LIVEKIT_API_KEY="${API_KEY}"
export LIVEKIT_API_SECRET="${API_SECRET}"

# create token for room "test-room", identity "tester"
lk token create --room test-room --identity tester
Use the returned token in your client (SDK or Web) with
ws://<VM_IP>:7880
. 1. Test RTMP ingress (OBS) • Create an ingress via CLI:
Copy code
cat > /tmp/ingress-create.json <<EOF
{
  "input_type": 0,
  "name": "test-ingress",
  "room_name": "test-room",
  "participant_identity": "ingress-bot",
  "participant_name": "Ingress Bot"
}
EOF

lk ingress create /tmp/ingress-create.json --url ${LIVEKIT_URL}
• Use OBS to stream to: rtmp//&lt;VM IP&gt;1935 and the returned stream key. 1. Test Egress (room composite)
Copy code
# start recording the room (room must exist and have participants)
lk egress start --type room-composite --room test-room --layout speaker --url ${LIVEKIT_URL}
Check egress logs for saving/upload events. 1. Test SIP (basic) • Verify SIP process listening:
Copy code
ss -u -lntp | grep :5060 || ss -tulnp | grep 5060
• Use a SIP client (Linphone) pointing to <VM_IP>:5060 to place a call into the configured SIP server or use
lk
sip helper if available. Important notes and next steps • This setup uses IP-only, no TLS. Do not expose sensitive workloads publicly without TLS or additional network protections. • Egress advanced features (composites requiring Chrome/GStreamer) may need host packages (Chrome, GStreamer). If you need them, I can provide the exact apt install commands and update the egress container run options. • If you want I can: (a) provide the expanded init script that installs Chrome/GStreamer and systemd unit wrappers, or (b) walk you step-by-step to run each section manually and verify. Which would you prefer? Sources: Self-hosting the Ingress Service | LiveKit docs | Self-hosting the Egress Service | LiveKit docs | Self-hosted SIP server | LiveKit docs | Deploy to a VM | LiveKit docs | Ports and firewall | LiveKit docs
b
should i want to mention my VM ip ?
t
Yes — you should insert your VM’s public IP wherever the script/configs use
<vm_ip>
or
${VM_IP}
. Why: • Services (LiveKit Server, Ingress, SIP, Egress) need the VM IP for RTC ICE, SIP RTP, Redis connections, and RTMP/WHIP endpoints so peers and other services can reach them. • With no domain, the public IP is the anchor for ws://, rtmp://, and SIP URIs. Where to put it (examples from the script/configs): •
livekit.yaml
— set
external_ip: <VM_IP>
and
redis.address: <VM_IP>:6379
•
egress.yaml
—
ws_url: ws://<VM_IP>:7880
,
redis.address: <VM_IP>:6379
•
ingress.yaml
—
ws_url: ws://<VM_IP>:7880
,
rtc_config.external_ip: <VM_IP>
•
sip.yaml
—
ws_url: ws://<VM_IP>:7880
,
redis.address: <VM_IP>:6379
,
external_ip: <VM_IP>
• Docker/env usage — set LIVEKIT_URL to
http://<VM_IP>:7880
and API vars accordingly. If you want, paste your VM IP here (or confirm you’ll replace placeholders) and I’ll update the exact script/config contents for you.
b
how to test live kit sip server
t
Regarding testing the LiveKit SIP server — here are clear, ordered steps to verify it’s running and to perform functional tests (CLI and SIP client). I assume your VM IP is set in the SIP config and the service is running in Docker as in the earlier script. 1) Verify the SIP service is running • Check Docker container: ◦ docker ps --filter name=livekit-sip • Check logs: ◦ docker logs -f livekit-sip • Confirm SIP port listening (UDP 5060): ◦ ss -u -lntp | grep 5060 ◦ or: sudo lsof -nP -iUDP:5060 2) Verify LiveKit Server connectivity • Ensure LiveKit Server accepts WebSocket connections: ◦ curl -v http//&lt;VM IP&gt;7880 • Check server logs: ◦ docker logs -f livekit-server 3) Create a test room and token (CLI) • Install CLI if not present: ◦ curl -sSL https://get.livekit.io | bash • Set env: ◦ export LIVEKIT_URL="http//&lt;VM IP&gt;7880" ◦ export LIVEKIT_API_KEY="YOUR_API_KEY" ◦ export LIVEKIT_API_SECRET="YOUR_API_SECRET" • Create a room and token: ◦ lk token create --room test-room --identity tester • Use that token in a Web client or SDK to join the room (optional) so you can observe SIP participant joining. 4) Use the LiveKit CLI to create a SIP participant (simulate incoming SIP call) • Command: ◦ lk sip create-participant --sip-uri sip:caller@<VM_IP>:5060 --room test-room --identity sip-user --url ${LIVEKIT_URL} --api-key ${LIVEKIT_API_KEY} --api-secret ${LIVEKIT_API_SECRET} • Watch livekit-sip logs for the call attempt: ◦ docker logs -f livekit-sip • The SIP participant should appear in the LiveKit room (check client or lk room list) 5) Test using a real SIP client (Linphone, Zoiper) • Configure the SIP client: ◦ SIP server / domain: <VM_IP> ◦ Port: 5060 ◦ Transport: UDP (or TCP if configured) ◦ Username/Password: none (unless you enabled auth) • Make a call to a SIP URI routed to LiveKit (example: sip:test@<VM_IP>:5060) or configure the client to call another test SIP endpoint that routes into LiveKit. • Observe: ◦ livekit-sip logs show incoming INVITE ◦ the participant joins the LiveKit room and you see media 6) Check RTP/media flow • Ensure UDP RTP port range from SIP config (e.g., 10000–20000) and WebRTC ports (50000–60000) are open in firewall. • Use tcpdump to observe RTP packets (optional): ◦ sudo tcpdump -i any udp and host <peer-ip> and port 10000-20000 7) Troubleshooting quick checks • If SIP INVITE not received: ◦ Ensure VM firewall/security group allows UDP 5060 and RTP port range. ◦ Confirm SIP client can reach <VM_IP>. • If call connects but no audio: ◦ Verify RTP ports open and NAT/external_ip is set correctly in sip.yaml. ◦ Check codecs supported on both sides; inspect logs for codec negotiation errors. • Check LiveKit and SIP logs for errors: ◦ docker logs livekit-sip ◦ docker logs livekit-server If you want, paste one example log line or the output of: • ss -u -lntp | grep 5060 • docker logs --tail 200 livekit-sip and I’ll help interpret it and guide the next fix.
b
i having working voice agent with livekit number and sip trunk
t
Thanks — helpful to know you have a working voice agent, LiveKit number, and SIP trunk. What exact help do you want next? Pick one or more so I provide targeted steps: • Test that inbound calls from the SIP trunk reach your voice agent (call flow verification) • Verify the SIP trunk registration/config and SIP INVITE handling (logs + SIP traces) • Troubleshoot call quality (packet loss, codecs, RTP ports) • Configure routing so calls to your LiveKit number go into a specific room/agent • Create automated test calls (SIPp) or simulate SIP via CLI • Interpret specific logs or tcpdump output (paste relevant lines) If you want me to start a verification checklist, share: 1) Your VM IP (or confirm you’ll replace it in examples) 2) Whether SIP trunk delivers to UDP 5060 or a different port/IP 3) A sample (sanitized) log snippet from
docker logs livekit-sip
showing an INVITE or error, or the output of: • ss -u -lntp | grep 5060 • docker logs --tail 200 livekit-sip Tell me which option and provide any of the info above and I’ll give step‑by‑step tests and commands.
b
i want to integrate this agent with my exisiting freeswitch also wants to test with microsip internal connection
t
Thanks — I can guide you step‑by‑step to integrate LiveKit SIP with FreeSWITCH and test with MicroSIP. A few quick clarifying questions so I give exact commands and config snippets: 1. Are FreeSWITCH and LiveKit running on the same host or on different hosts? 2. What is the public/private IP of the LiveKit SIP server (or confirm you’ll use the VM IP you mentioned)? 3. Does your SIP trunk to LiveKit require authentication (username/password) or is it unauthenticated (IP‑based)? 4. Which port/profile does FreeSWITCH use for inbound SIP from the trunk (default 5060 UDP/TCP)? 5. Do you want FreeSWITCH to forward calls into a specific LiveKit room/participant, or have LiveKit call into FreeSWITCH? Which direction(s)? 6. For MicroSIP testing, do you want to register MicroSIP to LiveKit SIP or to FreeSWITCH (or both)? Answer these and I’ll provide: • Exact FreeSWITCH dialplan and sip_profiles sample to route calls to LiveKit (or accept from it) • LiveKit SIP configuration examples for SIP trunking (auth or IP) • MicroSIP settings and test call steps to validate internal calls • Commands to capture and interpret SIP/RTP traffic and relevant log checks Which items do you want me to start with first?
b
Freeswitch and livekit are in different host use VM Ip i have mentioned is it unauthenticated (IP‑based) I'm using udp i want this kind execution Extension number → FreeSWITCH → LiveKit trunk → number +15183171307 → dispatch rule → AI agent in room. the extension number are dynmaic 4 digit
t
Great — I’ll give a concise, ordered checklist with exact config snippets and commands you can apply to integrate FreeSWITCH (separate host) with LiveKit SIP (your VM IP), use an IP‑based UDP trunk, route dynamic 4‑digit extensions to +15183171307, and test from MicroSIP. I’ll assume: • LiveKit SIP VM IP = YOUR_VM_IP (replace with your real IP) • FreeSWITCH host is reachable from the LiveKit VM • No SIP auth (IP-based trust) • UDP transport and default SIP port 5060 • RTP port range used by SIP = 10000–20000 If that’s correct, proceed with the steps below and replace YOUR_VM_IP and FREESWITCH_IP where indicated. 1) Open network ports • On LiveKit VM allow UDP 5060 and RTP range 10000–20000; also ensure LiveKit WebSocket port 7880 is accessible from services that need it. 2) Create an outbound trunk in LiveKit (allow your FreeSWITCH IP) • outbound-trunk.json:
Copy code
{
  "trunk": {
    "name": "freeswitch-trunk",
    "address": "FREESWITCH_IP",
    "transport": "SIP_TRANSPORT_UDP",
    "numbers": [
      "*"
    ],
    "allowed_addresses": [
      "FREESWITCH_IP/32"
    ],
    "media_encryption": "SIP_MEDIA_ENCRYPT_DISABLE"
  }
}
• Apply (using your CLI/SDK): lk sip outbound create outbound-trunk.json 3) Configure FreeSWITCH gateway to LiveKit • Create file: /usr/local/freeswitch/conf/sip_profiles/external/livekit.xml
Copy code
<include>
  <gateway name="livekit_trunk">
    <param name="proxy" value="YOUR_VM_IP:5060"/>
    <param name="register" value="false"/>
    <param name="from-domain" value="YOUR_VM_IP"/>
    <param name="retry-seconds" value="30"/>
    <param name="expire-seconds" value="600"/>
    <param name="register-transport" value="udp"/>
  </gateway>
</include>
• Reload in FS: fs_cli -x "reloadxml" 4) Dialplan to match dynamic 4‑digit extensions and send to LiveKit number • Example dialplan (place in dialplan/default/ or your context):
Copy code
<include>
  <context name="default">
    <extension name="route_4digit_to_livekit">
      <condition field="destination_number" expression="^\d{4}$"/>
      <action application="set" data="effective_caller_id_number=${caller_id_number}"/>
      <action application="set" data="sip_h_X-Extension=${destination_number}"/>
      <action application="bridge" data="sofia/gateway/livekit_trunk/+15183171307"/>
    </extension>
  </context>
</include>
• Reload dialplan: fs_cli -x "reloadxml" 5) Ensure LiveKit SIP config binds to external IP • On the LiveKit SIP config (sip.yaml) ensure: ◦ sip_port: 5060 ◦ use_external_ip: true ◦ external_ip: YOUR_VM_IP ◦ redis/ws url point to your LiveKit server (ws://YOUR_VM_IP:7880) 6) Create a LiveKit dispatch rule to map inbound call → room → agent • dispatch-rule.json:
Copy code
{
  "dispatch_rule": {
    "name": "freeswitch-agent-rule",
    "rule": {
      "dispatchRuleDirect": {
        "roomName": "agent-room"
      }
    },
    "roomConfig": {
      "agents": [
        {
          "agentName": "inbound-agent",
          "metadata": "from=freeswitch"
        }
      ]
    }
  }
}
• Apply: lk sip dispatch create dispatch-rule.json • Ensure your AI agent process connects and registers with agentName "inbound-agent". 7) Test flow from FreeSWITCH • From a FreeSWITCH extension (or MicroSIP registered to FreeSWITCH), dial a 4‑digit extension (e.g., 4000). • FreeSWITCH should bridge to sofia/gateway/livekit_trunk/+15183171307 and send SIP INVITE to YOUR_VM_IP:5060. 8) Observe and debug on LiveKit side • Tail SIP logs: docker logs -f livekit-sip (or journalctl if systemd) • Monitor SIP traffic: sudo tcpdump -n -i any port 5060 or udp and host FREESWITCH_IP • Confirm LiveKit creates the participant and dispatches the agent to room "agent-room". 9) Test MicroSIP (internal) • Register MicroSIP to FreeSWITCH (best flow): ◦ SIP server: FREESWITCH_IP, port 5060, transport UDP ◦ Username/password: a FreeSWITCH extension (e.g., 1000/1234) • From MicroSIP call the 4-digit extension (e.g., 4000). Call should flow FreeSWITCH → LiveKit → +15183171307 → dispatched agent. • Alternatively, Quick Call in MicroSIP to: +15183171307@YOUR_VM_IP (if LiveKit allowed your client IP) — but registration via FreeSWITCH is preferred. 10) RTP / audio troubleshooting • Confirm RTP ports open on both hosts (FreeSWITCH and LiveKit). For SIP media, check 10000–20000 on LiveKit and FreeSWITCH. • If audio one-way: verify external_ip is set on LiveKit SIP config and on FreeSWITCH SIP profile if NAT involved. • Use tcpdump to capture RTP: sudo tcpdump -n -i any udp portrange 10000-20000 11) Useful commands to share if you want me to interpret results • On LiveKit host: ◦ ss -u -lntp | grep 5060 ◦ docker logs --tail 200 livekit-sip ◦ tcpdump -n -i any port 5060 -c 100 • On FreeSWITCH host: ◦ fs_cli -x "sofia status" ◦ fs_cli -x "show channels" ◦ tcpdump capturing towards YOUR_VM_IP: sudo tcpdump -n host YOUR_VM_IP and port 5060 -c 100 If you want, paste: • FREESWITCH_IP and YOUR_VM_IP (or confirm you’ll substitute) • Output of ss -u -lntp | grep 5060 on both hosts • A short docker logs --tail 200 livekit-sip capture after attempting a test call I’ll interpret logs and give targeted next steps (NAT fixes, SDP codec issues, or dialplan adjustments). Which part should I help with now — applying configs, running a test, or reading logs? Sources: SIP APIs | LiveKit docs | Agent dispatch | LiveKit docs | Ports and firewall | LiveKit docs | Inbound calls with Twilio Voice | LiveKit docs | Using Wavix to accept and make calls | LiveKit docs