feat: fixed deploy script for setting up service for restarting

This commit is contained in:
Jet Pham 2025-06-06 19:34:29 -07:00
parent e761320bc7
commit baef052a4a
No known key found for this signature in database
4 changed files with 44 additions and 23 deletions

View file

@ -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"
# 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'"

View file

@ -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

View file

@ -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),
})
}

View file

@ -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 {