From baef052a4ab6a1269ffc05bf8bf6fa6dbbfd7f7a Mon Sep 17 00:00:00 2001 From: Jet Pham <55770902+jetpham@users.noreply.github.com> Date: Fri, 6 Jun 2025 19:34:29 -0700 Subject: [PATCH] feat: fixed deploy script for setting up service for restarting --- deploy.sh | 46 ++++++++++++++++++++++++++++++++++++++++++---- noisebell.service | 16 ---------------- src/discord.rs | 4 ++-- src/main.rs | 1 - 4 files changed, 44 insertions(+), 23 deletions(-) delete mode 100644 noisebell.service diff --git a/deploy.sh b/deploy.sh index 2292b4a..4e37431 100755 --- a/deploy.sh +++ b/deploy.sh @@ -6,12 +6,50 @@ set -e echo "Building for Raspberry Pi..." cross build --release --target aarch64-unknown-linux-gnu +# Check if Discord credentials are already set +if [ -z "$DISCORD_TOKEN" ]; then + echo "Please enter your Discord bot token:" + read -s DISCORD_TOKEN +fi + +if [ -z "$DISCORD_CHANNEL_ID" ]; then + echo "Please enter your Discord channel ID:" + read -s DISCORD_CHANNEL_ID +fi + +# Create service file with credentials +cat > noisebell.service << EOL +[Unit] +Description=Noisebell Discord Notification Service +After=network.target + +[Service] +Type=simple +User=noisebridge +WorkingDirectory=/home/noisebridge/noisebell +Environment=DISCORD_TOKEN=${DISCORD_TOKEN} +Environment=DISCORD_CHANNEL_ID=${DISCORD_CHANNEL_ID} +ExecStart=/home/noisebridge/noisebell/noisebell +Restart=always +RestartSec=10 + +[Install] +WantedBy=multi-user.target +EOL + echo "Copying to Raspberry Pi..." ssh noisebridge@noisebell.local "mkdir -p ~/noisebell" scp target/aarch64-unknown-linux-gnu/release/noisebell noisebridge@noisebell.local:~/noisebell/ -scp endpoints.json noisebridge@noisebell.local:/home/noisebridge/noisebell/endpoints.json +scp noisebell.service noisebridge@noisebell.local:~/noisebell/ -echo "Setting permissions" -ssh noisebridge@noisebell.local "chmod +x ~/noisebell/noisebell" +echo "Setting up service..." +ssh noisebridge@noisebell.local "sudo cp ~/noisebell/noisebell.service /etc/systemd/system/ && \ + sudo systemctl daemon-reload && \ + sudo systemctl enable noisebell && \ + sudo systemctl restart noisebell" -echo "Deployment complete!" +# Clean up local service file +rm noisebell.service + +echo "Deployment complete!" +echo "You can check the service status with: ssh noisebridge@noisebell.local 'sudo systemctl status noisebell'" diff --git a/noisebell.service b/noisebell.service deleted file mode 100644 index 1cf6c08..0000000 --- a/noisebell.service +++ /dev/null @@ -1,16 +0,0 @@ -[Unit] -Description=Noisebell Discord Notification Service -After=network.target - -[Service] -Type=simple -User=noisebridge -WorkingDirectory=/home/noisebridge/Documents/noisebell -Environment=DISCORD_TOKEN=your_bot_token_here -Environment=DISCORD_CHANNEL_ID=your_channel_id_here -ExecStart=/home/noisebridge/.cargo/bin/noisebell -Restart=always -RestartSec=10 - -[Install] -WantedBy=multi-user.target \ No newline at end of file diff --git a/src/discord.rs b/src/discord.rs index b593fa2..1b08fa7 100644 --- a/src/discord.rs +++ b/src/discord.rs @@ -3,7 +3,7 @@ use std::time::Instant; use anyhow::Result; use serenity::prelude::*; -use serenity::model::channel::ChannelId; +use serenity::model::id::ChannelId; use tracing::{info, error}; pub struct DiscordClient { @@ -32,7 +32,7 @@ impl DiscordClient { Ok(Self { client, - channel_id: ChannelId(channel_id), + channel_id: ChannelId::new(channel_id), }) } diff --git a/src/main.rs b/src/main.rs index 155bd40..3c1a02e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -50,7 +50,6 @@ async fn main() -> Result<()> { let callback = move |event: gpio::CircuitEvent| { info!("Circuit state changed: {:?}", event); - let discord_client = discord_client_clone.clone(); tokio::spawn(async move { if let Err(e) = discord_client.send_circuit_event(&event).await {