Docker Consolidation Project, Part Ten

Docker Consolidation Project, Part Ten
Photo by Anthony Gomez / Unsplash

Well I forgot about Automatic Server Reboots for DOCKER-01. Since I've consolidated the different applications from different servers on to one server it makes sense to have one script perform the remote reboot just once.

So on my fileserver I create the script reboot-mounted-servers.ps1

# reboot-mounted-servers.ps1

# If a Linux server has a CIFS mount from my fileserver the mount fails and does not refresh after the fileserver reboots.
# The intention of this script is have those linux servers reboot after fileserver comes back online.

# Utilizing Powershell to SSH into linux server
# This single command will SSH in to the server, and then reboot it.
# ssh -t username@FQDN "sudo reboot ; bash --login"
# This requires the user has the permissions to reboot

# Command to reboot DOCKER-01
# Server is running the following applications with mount points:
# Paperless-NGX, PhotoPrism, TubeArchivist
ssh -t -i c:\Users\Administrator.DOMAIN\.ssh\docker-01 [email protected] "sudo reboot ; bash --login"

I save the new file. The next step is to give the user david permission to reboot the server.

Steps performed on DOCKER-01

  • sudo nano /etc/sudoers
# Allow david to reboot
david ALL=NOPASSWD: /sbin/halt, /sbin/reboot, /sbin/shutdown
  • I save the sudoers file

Steps performed on fileserver via PowerShell

  • ssh -t -i c:\Users\Administrator.DOMAIN\.ssh\docker-01 [email protected] "sudo reboot ; bash --login"

I was able to verify that DOCKER-01 did reboot, my Windows Terminal session on desktop has closed.

So I open up Task Scheduler on my fileserver and create a new task that will begin the script At startup with a delay of 3 minutes. For the action I point it to my new reboot-mounted-servers.ps1. That will take care of this issue for me. Victory!