how to autoshutdown after closing a program (vice emulator)

I’m trying to get a commodore 64 emulator to autostart when I plug in my pi using dietpi, and then autoshutdown when I exit the emulation.

What I have done so far-
Installed dietpi and updated.
Used the retropie installation script to install the vice emulator (only) from source.
succeeded in making dietpi autologin.
succeeded in starting x64, the vice c64 emulator.

I did the autologin by slightly altering the /etc/inittab file and autostarting the emulator by slightly altering the /etc/rclocal file.

The changes to my /etc/inittab:

#1:2345:respawn:/sbin/getty --noclear 38400 tty1
1:2345:respawn:/bin/login -f root tty1 </dev/tty1 >/dev/tty1 2>&1

The changes to my /etc/rclocal

#/DietPi/dietpi/dietpi-services start
#/DietPi/dietpi/dietpi-banner 0
#echo -e " Default Login:\n Username = root\n Password = dietpi\n"
#exit 0

Never done anything like this before and am learning as I go. So I don’t know if I did this the best way or not, but this has succeeded in my being able to plug the pi in, and not touching it again until it is in emulation.

Now I would like to autoshutdown when the emulator is exited. I think maybe this can be simply done by slightly altering anther file because when I exit the emulator it wants me to log in and the little messages that pop up normally before log in (identifying the root and dietpi password and the options below that in the little list), reappear. But I haven’t found the file that has the lines that do it (the lines I added a # to in the rclocal file to comment them out - I believe these must reappear in another file since I see the same bit again when I exit the emulator).

But maybe a script of some sort would be the way to go? Not having done any of this before, I am uncertain?


I do have additional goals for this after the autoshutdown on emulation exit and if anyone can offer help with these goals as well it would be much appreciated. These are:

text silent boot and shutdown- all text replaced by splash screens or animation during startup and shutdown.

I need to figure out how to go in and change the config files of the emulator so it points to directories where disk images are stored for the games and maybe map some buttons to my logitech joystick a bit differently- would be nice to have one button do a reset on the emulator and another swap joystick ports and get rid of the thumbstick button that keeps bringing up the menu every time I get excited in a game and press down on the joystick accidentally. LOL

Anyway- any interest or help would be appreciated. If I can figure out the autoshutdown and get some splash screens going then maybe a image of the microsd card could be made available and c64 fans could have a nice little c64 machine for cheap. And then I could apply the stuff to an image for an amiga emulator and then have a nice little amiga machine for cheap.

I don’t see where anyone has done this yet and it seems such an obvious and fun thing to do to end up with a c64 and amiga that can simply be plugged in and the OS is hidden under the emulator the whole time. I would think these would be very popular microsd images.

Sounds fun!

/etc/rc.local runs last during boot. however, before login. So you wont be able to achieve what you want there. Also, dont disable any DietPi stuff, or you’ll encounter issues.
Lets put /etc/rc.local back to normal:

cat << _EOF_ > /etc/rc.local
#!/bin/sh -e
/DietPi/dietpi/dietpi-services start
/DietPi/dietpi/dietpi-banner 0
echo " Default Login:\n Username = root\n Password = dietpi\n"
exit 0

1st you’ll need to enable autologin login.
As your running Jessie, lets create a systemd service that enable autologin on tty1:

mkdir -p /etc/systemd/system/getty@tty1.service.d &> /dev/null
cat << _EOF_ > /etc/systemd/system/getty@tty1.service.d/autologin.conf
ExecStart=-/sbin/agetty --autologin root %I

Now to add the code that runs the emulator and shutdown on exit.
The file you need to modify is /root/.bashrc. This gets launched after the user logs in.

nano /root/.bashrc

After /DietPi/dietpi/login (at the end), add the following:


Reboot and test :slight_smile:

When /opt/retropie/emulators/vice/bin/x64 is run, the script will wait until it exits. Then the poweroff command will be run.

OK I’m now getting a message
[TIME] Timed out waiting for device dev-sda1.device.
[DEPEND] Dependency failed for /mnt/usb_1.

and then the system hangs and becomes unresponsive.

Ok so for kicks I tried a fresh install of dietpi on another card.
After setup I keep getting a repeating message on bootup:

cfg80211: Calling CRDA to update world regulatory domain

until I get :

cfg80211: exceeded CRDA call max attempts. Not calling CRDA

I think this is related to the problem in the previous post- might be my wireless? which is working fine when I log in- I can apt-update for example no problem, install git, etc.

This was fixed for v100. Once DietPi runs the update and reboots, the issue should disappear.

If the issue re-occurs after v100. Try running the following:

/DietPi/dietpi/dietpi-apt-get_update 2
apt-get install iw crda --no-install-recommends -y

If that doesnt fix it, you may need to manually enter your country code in /etc/default/crda

Did you have a USB drive attached during this boot? Could be power related.

Ok, so both were already updated to v 100

The only usb I have plugged in are a tiny wireless keyboard dongle, a joystick and a wireless wifi usb for internet. I unplugged the joystick and got the same results. The reason I feel the problem with the timout and the wifi are related is because earlier in the boot I got the message:

A start job is running for dev-sda1.device: Calling CRDA to update world regulatory domain

on a single line several times- or close to that, it flashes by faster than my slow typing so I’ve left off some numbers here.

So the dev-sda1.device is related to the problem and my hunch is that this is my usb wifi.


/DietPi/dietpi/dietpi-apt-get_update 2
apt-get install iw crda --no-install-recommends -y

appears to have fixed the hanging problem and the calling crda problem. I downloaded the latest image I could find on sourceforge and noticed it was not v100- maybe an available updated image would prevent the problem?

Autologin doesn’t appear to be working but I haven’t had time to go back and check that I made the file correctly, so later I’ll try running those commands again and give another update.

Ok, so after redoing everything I am back to:

[TIME] Timed out waiting for device dev-sda1.device.
[DEPEND] Dependency failed for /mnt/usb_1.

and then the system hangs and becomes unresponsive.

Interestingly, if I do not have the file for autologin, this does not happen- the system now starts and login is normal…


One more update, just in case it helps- I unplugged all usb devices including keyboard and rebooted and go the same message as above.

Also I tried manually entering the crda as US with same result.


if I remove the autoboot file, and boot and login normally, I type crda and get
COUNTRY environment variable not set.

even though I have edited the /etc/default/crda file as above.

Sounds like my problem is the same problem as on another thread.

Wondering why it is necessary to call the crda on boot? (Just curiosity- I’m a noob at this stuff).

Thank you

Yep, cdra is a mandatory program that sets your Wifi region during boot. Basically, its against the “law” to use some channels in some countries (eg: UK channel 14 is not allowed).

/etc/default/crda seems to do nothing as you and Gordon mentioned. I’am looking into this at the moment.

As for the /dev/sda1, you can safely ignore it. This is because SystemD doesn’t like duplicate fstab entries. DietPi tries to mount /dev/sda1 as ext4, then ntfs. If it bugs you that much, you can disable the /dev/sda1 mount in /etc/fstab.

Regarding the autologin. Try running dietpi-config > AutoBoot options and select Kodi. You’ll receive an error during boot as Kodi wont be available, however, this will allow your system to auto login.
If this doesnt work, you will need to roll back any system settings you have applied in regards to autologin, then try again.

If it bugs you that much, you can disable the /dev/sda1 mount in /etc/fstab

Naw- I just thought (incorrectly) that is why it was hanging and freezing up when trying to autologin.

OK- so, I removed the little autologin file we created earlier in this thread (/etc/systemd/system/getty@tty1.service.d/autologin.conf), and used the kodi autologin.

I didn’t see an error- but maybe it just scrolled by without my notice.

I’d say my problem is solved and everything works great!

Quick recap for anyone interested in doing this with some other app-

Use the diet-pi config autologin option to select kodi

Then do modify is /root/.bashrc.

After /DietPi/dietpi/login (at the end), add the following:

/opt/retropie/emulators/vice/bin/x64 (Or whatever program you want to autorun when the machine turns on)


Watching it turn on and boot straight into the emulation is like so much magic to me! It’s so cool now that it is working!

i REALLY appreciate your taking your time helping me!

With dietpi I can have the emulation and all the games, etc for the c64 I can find and still have lots of room left over on a 2gb microsd card.

So cool!

Now I’ve got to do this with the amiga emulation and figure out the rest of my wishlists like boot splash screens.

No worries, have fun :slight_smile: