Skip to content

Commit

Permalink
yay - desktop infra done for october
Browse files Browse the repository at this point in the history
  • Loading branch information
adnan wahab committed Oct 18, 2024
1 parent 053193f commit fb01c27
Show file tree
Hide file tree
Showing 4 changed files with 237 additions and 80 deletions.
116 changes: 65 additions & 51 deletions scripts/_bootstrap.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# run this on jetson to install hashirama platform
# divide - install.sh + bootstrap.sh -blah;adlgapsdok


# run this on jetson to install hashirama platform + desktop

#sudo apt-get install -y nvidia-container-toolkit
#git clone --depth 1 https://github.com/doomemacs/doomemacs ~/.config/emacs
Expand All @@ -13,80 +16,91 @@
# sudo systemctl enable docker
# sudo usermod -aG docker $USER

#find / -name Caddyfile 2>/dev/null
#ls -la /etc/caddy/
#sudo rm /etc/caddy/Caddyfile
#sudo ln -s /home/adnan/homelab_status_page/scripts/infra/caddy/Caddyfile /etc/caddy/Caddyfile

#caddy


#### cleanup after this line

#NOTE TODO -> sync all passwords + keys + secrets + etc

#Update Docker's daemon.json to set the default runtime to nvidia
if [ -f /etc/docker/daemon.json ]; then
sudo jq '. + {"runtimes": {"nvidia": {"path": "nvidia-container-runtime", "runtimeArgs": []}}, "default-runtime": "nvidia"}' /etc/docker/daemon.json | sudo tee /etc/docker/daemon.json.tmp
sudo mv /etc/docker/daemon.json.tmp /etc/docker/daemon.json
else
echo '{"runtimes": {"nvidia": {"path": "nvidia-container-runtime", "runtimeArgs": []}}, "default-runtime": "nvidia"}' | sudo tee /etc/docker/daemon.json
fi
# if [ -f /etc/docker/daemon.json ]; then
# sudo jq '. + {"runtimes": {"nvidia": {"path": "nvidia-container-runtime", "runtimeArgs": []}}, "default-runtime": "nvidia"}' /etc/docker/daemon.json | sudo tee /etc/docker/daemon.json.tmp
# sudo mv /etc/docker/daemon.json.tmp /etc/docker/daemon.json
# else
# echo '{"runtimes": {"nvidia": {"path": "nvidia-container-runtime", "runtimeArgs": []}}, "default-runtime": "nvidia"}' | sudo tee /etc/docker/daemon.json
# fi


# Add data-root configuration to Docker's daemon.json
if [ -f /etc/docker/daemon.json ]; then
sudo jq '. + {"data-root": "/mnt/docker"}' /etc/docker/daemon.json | sudo tee /etc/docker/daemon.json.tmp
sudo mv /etc/docker/daemon.json.tmp /etc/docker/daemon.json
else
echo '{"data-root": "/mnt/docker"}' | sudo tee /etc/docker/daemon.json
fi
# # Add data-root configuration to Docker's daemon.json
# if [ -f /etc/docker/daemon.json ]; then
# sudo jq '. + {"data-root": "/mnt/docker"}' /etc/docker/daemon.json | sudo tee /etc/docker/daemon.json.tmp
# sudo mv /etc/docker/daemon.json.tmp /etc/docker/daemon.json
# else
# echo '{"data-root": "/mnt/docker"}' | sudo tee /etc/docker/daemon.json
# fi


# Restart Docker to apply changes
# # Restart Docker to apply changes

git clone https://github.com/dusty-nv/jetson-containers
# git clone https://github.com/dusty-nv/jetson-containers

sudo systemctl restart docker
bash jetson-containers/install.sh
# sudo systemctl restart docker
# bash jetson-containers/install.sh


hello() {
echo "hello"
curl -fsSL https://bun.sh/install | bash
source /home/adnan/.bashrc
# hello() {
# echo "hello"
# curl -fsSL https://bun.sh/install | bash
# source /home/adnan/.bashrc

}
# }

install_rustdesk() {
# Update package list and install dependencies
sudo apt-get update
sudo apt-get install -y wget gdebi-core
# install_rustdesk() {
# # Update package list and install dependencies
# sudo apt-get update
# sudo apt-get install -y wget gdebi-core

# Download the RustDesk .deb package
wget https://github.com/rustdesk/rustdesk/releases/download/1.1.9/rustdesk-1.1.9.deb
# # Download the RustDesk .deb package
# wget https://github.com/rustdesk/rustdesk/releases/download/1.1.9/rustdesk-1.1.9.deb

# Install the RustDesk package
sudo gdebi -n rustdesk-1.1.9.deb
# # Install the RustDesk package
# sudo gdebi -n rustdesk-1.1.9.deb

# Clean up the downloaded .deb file
rm rustdesk-1.1.9.deb
# # Clean up the downloaded .deb file
# rm rustdesk-1.1.9.deb

echo "RustDesk installation completed."
}
# echo "RustDesk installation completed."
# }

# Call the function to install RustDesk
install_rustdesk
# # Call the function to install RustDesk
# install_rustdesk


#sudo docker run --runtime nvidia -it --rm --network=host dustynv/l4t-pytorch:r36.2.0
# #sudo docker run --runtime nvidia -it --rm --network=host dustynv/l4t-pytorch:r36.2.0

#et
#tailscale
# #et
# #tailscale

#nix ??
#_wahab
# #nix ??
# #_wahab

#mkdir unreal
# wget ->
# unzip
#
# https://zed.dev/docs/remote-development adnan@jetson-orin:~$ zed
# #mkdir unreal
# # wget ->
# # unzip
# #
# # https://zed.dev/docs/remote-development adnan@jetson-orin:~$ zed

# bootstraps a server like tailscale, ollama, etc
# # bootstraps a server like tailscale, ollama, etc

# docker pull ollama/ollama
# docker run -it --gpus all ollama/ollama
sudo apt-get update && sudo apt-get install v4l2loopback-dkms
# # docker pull ollama/ollama
# # docker run -it --gpus all ollama/ollama
# sudo apt-get update && sudo apt-get install v4l2loopback-dkms


# adnan@jetson-orin:~$ docker run --runtime nvidia --rm -it \
Expand Down
3 changes: 3 additions & 0 deletions scripts/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@


# hardcode my parameters to desktop
88 changes: 68 additions & 20 deletions scripts/infra/caddy/Caddyfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
{
email [email protected]
log {
output file /var/log/caddy/caddy.log {
Expand All @@ -8,29 +8,77 @@
}
level DEBUG
}

}

files.hashirama.blog {
root * /home/adnan/Videos
file_server browse
header Access-Control-Allow-Origin *
header Access-Control-Allow-Methods "GET, POST, OPTIONS"
header Access-Control-Allow-Headers "Content-Type"
#respond "hi world"

root * /home/adnan/derp
file_server browse
header Access-Control-Allow-Origin *
header Access-Control-Allow-Methods "GET, POST, OPTIONS"
header Access-Control-Allow-Headers "Content-Type"
}

hashirama.blog {
tls {
dns cloudflare {env.CLOUDFLARE_API_TOKEN}
resolvers 1.1.1.1
}

header Access-Control-Allow-Origin *
header Access-Control-Allow-Methods "GET, POST, OPTIONS"
header Access-Control-Allow-Headers "Content-Type"
reverse_proxy localhost:8080

# Add logging for this site
log {
output file /home/adnan/derp/log/caddy/hashirama.blog.log {
roll_size 10MiB
roll_keep 5
roll_gzip
}
}
}

jupyter.hashirama.blog {
tls {
dns cloudflare {env.CLOUDFLARE_API_TOKEN}
resolvers 1.1.1.1
}
#
# jupyter.hashirama.blog {
# tls {
# dns cloudflare {env.CLOUDFLARE_API_TOKEN}
# resolvers 1.1.1.1
# }
# #respond "hi world"
# header Access-Control-Allow-Origin *
# header Access-Control-Allow-Methods "GET, POST, OPTIONS"
# header Access-Control-Allow-Headers "Content-Type"
# reverse_proxy localhost:8888
# }
# llama-tools.com {
# # tls {
# # dns cloudflare {env.CLOUDFLARE_API_TOKEN}
# # resolvers 1.1.1.1
# # }
# #respond "hi world"
# # header Access-Control-Allow-Origin *
# # header Access-Control-Allow-Methods "GET, POST, OPTIONS"
# # header Access-Control-Allow-Headers "Content-Type"
# # reverse_proxy localhost:8080
# #reverse_proxy localhost:8080
# respond "hi world"
# }
# files.hashirama.blog {
# tls {
# dns cloudflare {env.CLOUDFLARE_API_TOKEN}
# resolvers 1.1.1.1
# }
# respond "hi world"
# }
#respond "hi world"
# header Access-Control-Allow-Origin *
# header Access-Control-Allow-Methods "GET, POST, OPTIONS"
# header Access-Control-Allow-Headers "Content-Type"
# reverse_proxy localhost:8080

#respond "hi world"
header Access-Control-Allow-Origin *
header Access-Control-Allow-Methods "GET, POST, OPTIONS"
header Access-Control-Allow-Headers "Content-Type"
reverse_proxy localhost:8888
}
#reverse_proxy localhost:8080
# log {
# output file /var/log/caddy/access.log
# level INFO
# }
110 changes: 101 additions & 9 deletions scripts/restart-blog.sh
Original file line number Diff line number Diff line change
@@ -1,20 +1,112 @@
#!/bin/bash
# Display the Caddy service file
#echo "Displaying the Caddy service file..."
# cat /etc/systemd/system/caddy.service
# [Unit]
# Description=Caddy web server
# After=network.target
# [Service]
# Environment=HOME=/home/adnan
# ExecStart=/usr/local/bin/caddy run --config /etc/caddy/Caddyfile --adapter caddyfile
# ExecReload=/usr/local/bin/caddy reload --config /etc/caddy/Caddyfile --adapter caddyfile
# Restart=on-failure
# [Install]
# WantedBy=multi-user.target
# Find the Caddy log file
#curl -I https://hashirama.blog
#curl ifconfig.me
# Function to check if Caddy is running

# admin dahboard to be public
# Check if the Caddyfile has good syntax
echo "Checking Caddyfile syntax..."
sudo caddy validate --config /etc/caddy/Caddyfile --adapter caddyfile || {
echo "Caddyfile has syntax errors."
exit 1
}

sudo caddy reload --config /etc/caddy/Caddyfile

check_caddy_status() {
if systemctl is-active --quiet caddy; then
echo "Caddy is running."
else
echo "Error: Caddy is not running."
sudo systemctl status caddy
exit 1
fi
}

# Check if Caddy is already running before stopping it
if systemctl is-active --quiet caddy; then
echo "Stopping Caddy service..."
sudo systemctl stop caddy
else
echo "Caddy is not running, skipping stop."
fi

# Reload system daemon (only needed if you changed systemd unit files)
echo "Reloading system daemon (if necessary)..."
sudo systemctl daemon-reload

# sudo systemctl stop homelab-status-page
# Format Caddyfile
echo "Formatting Caddyfile..."
sudo caddy fmt --overwrite /etc/caddy/Caddyfile || {
echo "Error formatting Caddyfile."
exit 1
}

# Start Caddy service
echo "Starting Caddy service..."
sudo systemctl start caddy || {
echo "Error starting Caddy service."
exit 1
}

# Check Caddy status
echo "Checking Caddy status..."
check_caddy_status

# Enable Caddy service to start on boot (if not already enabled)
if systemctl is-enabled --quiet caddy; then
echo "Caddy service already enabled on boot."
else
echo "Enabling Caddy service to start on boot..."
sudo systemctl enable caddy || {
echo "Error enabling Caddy service."
exit 1
}
fi

# Reload Caddy configuration (optional, Caddy reloads on start by default)
echo "Reloading Caddy configuration..."
sudo caddy reload --config /etc/caddy/Caddyfile || {
echo "Error reloading Caddy configuration."
exit 1
}

# Final status check
echo "Performing final status check..."
check_caddy_status



# sudo systemctl start homelab-status-page

# sudo systemctl enable homelab-status-page
echo "Checking Caddy logs..."
log_file=$(sudo find /var/log/caddy -name "caddy.log" 2>/dev/null)

sudo systemctl stop caddy
if [ -n "$log_file" ]; then
echo "Caddy log file found at: $log_file"
# Optionally, you can add a command to display the last few lines of the log
# sudo tail -n 20 "$log_file"
else
echo "Caddy log file not found. Checking journalctl logs..."
sudo journalctl -u caddy -n 50 --no-pager
fi

sudo systemctl start caddy
echo "Restart process completed."

sudo systemctl enable caddy
# Display the Caddy service file (if needed for debugging)
# echo "Displaying the Caddy service file..."
# cat /etc/systemd/system/caddy.service

sudo systemctl status caddy #& sudo systemctl status homelab-status-page
#mamba activate sam
# Log file check: Caddy typically logs via systemd's journal, but you can check for file logs

0 comments on commit fb01c27

Please sign in to comment.