Reboot After Install Inconsistent Behavior

Having issues with your DietPi installation or found a bug? Post it here.
Post Reply
User avatar
vnzkay
Posts: 10
Joined: Thu May 20, 2021 6:42 pm
Location: Los Angeles, CA
Contact:

Reboot After Install Inconsistent Behavior

Post by vnzkay »

I'm working towards a truly handsfree/headless setup process (and then documenting it as a tutorial). This is the first in a series of questions I'll post here; the conclusion will hopefully be a streamlined, hands-free flash-/initialize-board process. Happy to share what I end up with.

Where would the cleanest "reboot-after-install" point be? In order to cleanly register a custom-hostname board on a network, I'd like to reboot it after the first-boot setup succeeds. Is there a good place to do that?

Adding a `reboot` at the end of Automation_Custom_Script.sh works well for the ARM-64 bit image, but causes the ARM-32 bit image to restart the install process over.
User avatar
Joulinar
Posts: 5604
Joined: Sat Nov 16, 2019 12:49 am

Re: Reboot After Install Inconsistent Behavior

Post by Joulinar »

@MichaIng
if I'm not mistaken, we had a similar request in the near past about the point where to perform an automated reboot on first install. But I could not remember the exact case.
Pls let us know if a solution is working. This could help others if they hit by similar situation. Your DietPi Team
User avatar
MichaIng
Site Admin
Posts: 3201
Joined: Sat Nov 18, 2017 6:21 pm

Re: Reboot After Install Inconsistent Behavior

Post by MichaIng »

Ah yes that is true. I actually wanted to change that already, done now: https://github.com/MichaIng/DietPi/comm ... 190e24dc3b

As a workaround, do

Code: Select all

echo 2 > /boot/dietpi/.install_stage
in your Automation_Custom_Script.sh.
papasmurf
Posts: 6
Joined: Thu May 27, 2021 9:01 pm

Re: Reboot After Install Inconsistent Behavior

Post by papasmurf »

I my setup process, I want the Pi to reboot after the basic setup, and then continue running a custom setup script for other things I want to be installed.
If possible, I want to have this fully automated, no manual steps in between.

The reason is that I change the hostname in dietpi.txt. In my custom scripts I assume the new hostname to be active, so that needs a reboot first.

What would be the best way to achieve this?
User avatar
MichaIng
Site Admin
Posts: 3201
Joined: Sat Nov 18, 2017 6:21 pm

Re: Reboot After Install Inconsistent Behavior

Post by MichaIng »

For the script-internal environment hostname <hostname> can be used to set it immediately, but I'm not sure how thoroughly the effect is on the parent shell. But worth to give it a try to skip the additional reboot.

If you need a reboot, to not repeat all the other firstrun setup steps, I'd go with the above solution to force a reboot, but before that, place the second part of your script/steps to /var/lib/dietpi/postboot.d/<script_name>. Scripts in this directory are automatically executed by dietpi-postboot.service, running at the end of the boot process (but before the login prompt). The script could then (re)move itself as last step, to not be repeated on subsequent boots.

So like this:

Code: Select all

#!/bin/bash

# Steps to run now
... first part of custom setup steps

# Create script for steps to run after reboot
cat << '_EOF_' > /var/lib/dietpi/postboot.d/custom_script_part2
#!/bin/bash

... second part of custom setup steps

# This script shall run only once
rm /var/lib/dietpi/postboot.d/custom_script_part2
_EOF_

# Do not repeat firstrun setup despite manual reboot
echo 2 > /boot/dietpi/.install_stage

# Failsafe, force sync to disk
sync

reboot
papasmurf
Posts: 6
Joined: Thu May 27, 2021 9:01 pm

Re: Reboot After Install Inconsistent Behavior

Post by papasmurf »

Thanks.

I investigated the hostname, and a reboot is really required. Otherwise, the `hostname` command still returns the default DietPi name.

In the meantime I have a solution that works, but it has still an issue.

Code: Select all

#!/bin/bash
hs=`hostname`
if [ "$hs" == "nosey" ]; then
	echo `date` start running jansible bootstrap | tee -a /var/tmp/dietpi/logs/bootstrap.log
	curl https://gitlab.com/janvv/jansible/-/raw/main/bootstrap | bash -s -- -p <my-ansible-vault-pwd>
	echo `date` ready running jansible bootstrap | tee -a /var/tmp/dietpi/logs/bootstrap.log
	rm -rf /boot/Automation_Custom_Script.sh
	rm -rf /boot/AUTO_CustomScript.sh
	rm -rf /var/lib/dietpi/license.txt
else
	echo `date` reboot | tee -a /var/tmp/dietpi/logs/reboot.log
	reboot
fi
So this forces a reboot if the hostname is not active yet.
The mechanism works perfect, but then I run into another issue: in my Ansible playbook I do install additional software depending on the hostname.
I made an Ansible role that runs 'dietpi-software install <number>' .
This command gives an error, because dietpi-software is still in memory, because it is finalizing the setup process. The Ansible steps fail with the error message that dietpi-software is already running.

In the end all is good. Part of my setup is to configure a cron job that checks each 15 minutes if the Ansible plays needs to run.
But still... it would be nice to have it running successfully the first time.
User avatar
Joulinar
Posts: 5604
Joined: Sat Nov 16, 2019 12:49 am

Re: Reboot After Install Inconsistent Behavior

Post by Joulinar »

yes correct, you are not able to run dietpi-software multiple times. This is to avoid inconsistency due to concurrent runs.
Pls let us know if a solution is working. This could help others if they hit by similar situation. Your DietPi Team
User avatar
MichaIng
Site Admin
Posts: 3201
Joined: Sat Nov 18, 2017 6:21 pm

Re: Reboot After Install Inconsistent Behavior

Post by MichaIng »

Great that the script works.

Why don't you install the additional software on first boot by adding related AUTO_SETUP_INSTALL_SOFTWARE_ID= entries to dietpi.txt? Much cleaner and less overhead :). Otherwise you could do a

Code: Select all

while pgrep dietpi-software > /dev/null; do sleep 1; done
to wait until the other dietpi-software instance has finished.
Post Reply