feat: fixed deploy script for setting up service for restarting
This commit is contained in:
parent
e761320bc7
commit
baef052a4a
4 changed files with 44 additions and 23 deletions
44
deploy.sh
44
deploy.sh
|
|
@ -6,12 +6,50 @@ set -e
|
||||||
echo "Building for Raspberry Pi..."
|
echo "Building for Raspberry Pi..."
|
||||||
cross build --release --target aarch64-unknown-linux-gnu
|
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..."
|
echo "Copying to Raspberry Pi..."
|
||||||
ssh noisebridge@noisebell.local "mkdir -p ~/noisebell"
|
ssh noisebridge@noisebell.local "mkdir -p ~/noisebell"
|
||||||
scp target/aarch64-unknown-linux-gnu/release/noisebell noisebridge@noisebell.local:~/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"
|
echo "Setting up service..."
|
||||||
ssh noisebridge@noisebell.local "chmod +x ~/noisebell/noisebell"
|
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 "Deployment complete!"
|
||||||
|
echo "You can check the service status with: ssh noisebridge@noisebell.local 'sudo systemctl status noisebell'"
|
||||||
|
|
|
||||||
|
|
@ -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
|
|
||||||
|
|
@ -3,7 +3,7 @@ use std::time::Instant;
|
||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use serenity::prelude::*;
|
use serenity::prelude::*;
|
||||||
use serenity::model::channel::ChannelId;
|
use serenity::model::id::ChannelId;
|
||||||
use tracing::{info, error};
|
use tracing::{info, error};
|
||||||
|
|
||||||
pub struct DiscordClient {
|
pub struct DiscordClient {
|
||||||
|
|
@ -32,7 +32,7 @@ impl DiscordClient {
|
||||||
|
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
client,
|
client,
|
||||||
channel_id: ChannelId(channel_id),
|
channel_id: ChannelId::new(channel_id),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -50,7 +50,6 @@ async fn main() -> Result<()> {
|
||||||
|
|
||||||
let callback = move |event: gpio::CircuitEvent| {
|
let callback = move |event: gpio::CircuitEvent| {
|
||||||
info!("Circuit state changed: {:?}", event);
|
info!("Circuit state changed: {:?}", event);
|
||||||
|
|
||||||
let discord_client = discord_client_clone.clone();
|
let discord_client = discord_client_clone.clone();
|
||||||
tokio::spawn(async move {
|
tokio::spawn(async move {
|
||||||
if let Err(e) = discord_client.send_circuit_event(&event).await {
|
if let Err(e) = discord_client.send_circuit_event(&event).await {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue