Skip to content

Commit

Permalink
Add scripts to create and enable systemd service files
Browse files Browse the repository at this point in the history
  • Loading branch information
marvinmartian committed Nov 21, 2023
1 parent 3394d28 commit fbf6928
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 0 deletions.
35 changes: 35 additions & 0 deletions create_player_service.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/bin/bash

# Get the current working directory
CURRENT_DIR="$(pwd)"

# Define the service file content
SERVICE_CONTENT="[Unit]
Description=Go Music Player Service
After=network.target
[Service]
ExecStart=$CURRENT_DIR/player/go_player
WorkingDirectory=$CURRENT_DIR/player
User=melvin
Group=melvin
Restart=always
[Install]
WantedBy=multi-user.target"

# Specify the path for the service file
SERVICE_FILE_PATH="/etc/systemd/system/go_music_player.service"

# Print the service content to the file
echo "$SERVICE_CONTENT" | sudo tee "$SERVICE_FILE_PATH" > /dev/null

# Inform the user that the file has been created
echo "Service file created at $SERVICE_FILE_PATH"

# Reload systemd to pick up the new service file
sudo systemctl daemon-reload

# Enable and start the service
sudo systemctl enable go_music_player.service
sudo systemctl start go_music_player.service
36 changes: 36 additions & 0 deletions create_reader_service.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/bash

# Get the current working directory
CURRENT_DIR="$(pwd)"

# Define the service file content
SERVICE_CONTENT="[Unit]
Description=Yoda RFID Reader
After=network.target go-music-player.service
Wants=go-music-player.service
[Service]
ExecStart=$CURRENT_DIR/.venv/bin/python $CURRENT_DIR/reader/read.py
WorkingDirectory=$CURRENT_DIR/reader/
User=melvin
Group=melvin
Restart=always
[Install]
WantedBy=multi-user.target"

# Specify the path for the service file
SERVICE_FILE_PATH="/etc/systemd/system/yoda_rfid_reader.service"

# Print the service content to the file
echo "$SERVICE_CONTENT" | sudo tee "$SERVICE_FILE_PATH" > /dev/null

# Inform the user that the file has been created
echo "Service file created at $SERVICE_FILE_PATH"

# Reload systemd to pick up the new service file
sudo systemctl daemon-reload

# Enable and start the service
sudo systemctl enable yoda_rfid_reader.service
sudo systemctl start yoda_rfid_reader.service

0 comments on commit fbf6928

Please sign in to comment.