MicWit
Posts: 91
Joined: Fri Nov 01, 2013 5:20 am

Shut down and reboot

Tue Mar 11, 2014 6:51 am

I use sudo poweroff to turn off my system, sudo reboot to reboot it.

I want to change an external drive (in a duel docking bay), and if I turn it off mysql freaks out as the data dir is on the other drive (sucks that I cant eject just one drive!). So I would need to reboot anyhow. For mysql's sanity, I may as well shut down the computer, swap out the backup drive and then reboot it.

Of course, there is no power button on the pi, you have to unplug it and plug it back in (and my pi is going to be behind stuff). So I was wondering if there was some way of using the poweroff or shutdown command, to power off the system, and then turn it back on 2 mins later? That way I can make a desktop icon that will shut it down, I swap out the backup drive, and then a min or 2 later it will automatically reboot.

Any ideas?

User avatar
rpdom
Posts: 17029
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: Shut down and reboot

Tue Mar 11, 2014 7:45 am

I don't think that is possible in software.

However, if it is only MySQL that complains when the drive is offline, you could always stop the MySQL server, unmount the drive(s), display a message saying to swap them now - press Enter to continue, then mount the drives again and restart the server software.

Something along the lines of

Code: Select all

#!/bin/bash

# Set this to the mount point of the drive
DATADIR="/var/lib/mysql"

# Stop MySQL
sudo /etc/init.d/mysql stop
sudo umount $DATADIR

printf "OK to swap disks now. Press Enter when ready to restart "
read junk

# Start MySQL
sudo mount $DATADIR
sudo /etc/init.d/mysql start

echo "Done."
You would have to add mount/umount commands for any other mount points on those disks, and stop/start any other services that use them.

This method would be faster than a shutdown/reboot and it won't affect anything else that is running (unless it uses MySQL)

MicWit
Posts: 91
Joined: Fri Nov 01, 2013 5:20 am

Re: Shut down and reboot

Wed Mar 12, 2014 11:27 am

I like this idea, and am mucking around with it. The issue I am having is how to remount the disks?? It is a duel docking station, so there will be 2 disks in it. They are /dev/sda and /dev/sdb each with just the 1 partition, mounted at /media/data and /media/backup.

So to unmount, it would be umount /media/data for example. But once the drives have been turned off and back on again, how can I re-mount them in the same location (with a different drive for backup, though the same mount point, so shouldnt matter)?

Thaddy
Posts: 174
Joined: Wed Mar 06, 2013 11:28 am

Re: Shut down and reboot

Wed Mar 12, 2014 1:00 pm

Checkout the watchdog timer. That can do a reboot from power down as long as the power-supply is not interrupted, I believe.

User avatar
MattHawkinsUK
Posts: 538
Joined: Tue Jan 10, 2012 8:48 pm
Location: UK
Contact: Website

Re: Shut down and reboot

Wed Mar 12, 2014 3:56 pm

You can use the P6 header to reset the Pi after it has shutdown. It saves you needing to unplug the power cable. Requires a push-to-make switch to be soldered to the PCB.
My Raspberry Pi blog and home of the BerryClip Add-on board : http://www.raspberrypi-spy.co.uk/
Follow me on Google+, Facebook, Pinterest and Twitter (@RPiSpy)

MicWit
Posts: 91
Joined: Fri Nov 01, 2013 5:20 am

Re: Shut down and reboot

Thu Mar 13, 2014 5:12 am

Thanks for the hints, will keep an eye out on this. For now, I have written some scripts that can halt everything I need to (checking if a backup is in progress first) and unmount the drives. It will then mount the drives again once you click the OK button to say that you have powered them up again :)

Return to “Raspberry Pi OS”