Skip to content

Instantly share code, notes, and snippets.

@diogoalexsmachado
Created February 20, 2024 01:35
Show Gist options
  • Save diogoalexsmachado/4b71accfb3c6359a6dd5b905c5013343 to your computer and use it in GitHub Desktop.
Save diogoalexsmachado/4b71accfb3c6359a6dd5b905c5013343 to your computer and use it in GitHub Desktop.
Startup Script for WD Home NAS + Docker compose start
#!/bin/bash
# Wait for LAN to be available
while ! ping -c 1 192.168.0.1 >/dev/null; do
sleep 1
done
# Change directory
cd Desktop/docker_radarr/
# Stop docker-compose services
docker-compose stop
# Unmount the network drive
sudo umount /mnt/wdcloud
# Mount the network drive
sudo mount -t cifs -o username=USERNAME,password=PASSWORD,vers=3,uid=1000,gid=1000 //192.168.0.123/diogomachado /mnt/wdcloud
# Start docker-compose services
docker-compose start
@diogoalexsmachado
Copy link
Author

How to add to startup (Debian based OS's, using systemd):

  1. Create a systemd service unit file:
sudo nano /etc/systemd/system/startup_script.service
  1. Add the following content to the file:
[Unit]
Description=Startup Script
Wants=network-online.target
After=network-online.target

[Service]
Type=simple
ExecStart=/path/to/your/script/startup_script.sh

[Install]
WantedBy=default.target
  1. Replace /path/to/your/script/startup_script.sh with the actual path to your script.

  2. Save the file by pressing Ctrl + X, then Y, and finally Enter to confirm.

  3. Reload systemd to read the new unit file:

sudo systemctl daemon-reload
  1. Enable the service to run at startup:
sudo systemctl enable startup_script.service
  1. Reboot your system to apply the changes:
sudo reboot

@diogoalexsmachado
Copy link
Author

Note: do not forget to make startup_script.sh executable:

chmod+x startup_script.sh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment