Dietpi: Python script at startup (dietpi config) will never let you abort it

Created on 29 Nov 2018  ยท  3Comments  ยท  Source: MichaIng/DietPi

Creating a bug report/issue:

I am not sure if this is a bug, but dietpi soft should have an option like boot up types before running that script at startup to revert it, does it have?

I have a python script running without login at startup, created with the dietpi options (last one) to run anything at startup, now I cant even close it with Ctrl+C, how can I revert it without using a second linux PC to edit files?

thanks in advance

Question

All 3 comments

@joyeriastv
You man you use dietpi-postboot with /var/lib/dietpi/postboot.d/* to start your script?

Since postboot is started via systemd unit, is is executed non-interactively outside of terminal. You should only use this for oneshot scripts that themself exit. If you want to start a script that stay running interactively, you should do start on login, e.g. via: /etc/profile.d/*.sh
I'm not aware of a method to run a script interactively on terminal, but before actually login.

Another possibility is to create an own systemd unit to start at desired boot stage. It will be always non-interactive but you are able to stop it via: systemd stop servive_name
โ‚ฌ: See below, didn't read carefully before ๐Ÿ˜….

Okay, just read the issue on the forum (I guess this is yours as well?): https://dietpi.com/phpbb/viewtopic.php?f=11&t=5285

I understood now that it is not only a question but urgent help request ๐Ÿ˜‰.
If you added the script to autostart via dietpi-config, then it must be dietpi-autostart, which starts the script via systemd unit prior/regardless of login.

To stop it: systemctl stop dietpi-autostart_custom ๐Ÿ˜„
Generally you can use htop to kill (background) processes as well. The above is the "soft" way for systemd services.


About "how to do properly next time":

  • If the service is meant to run until it is manually stopped, and it should start on boot, prior or regardless of login, there is not "better" way. Just note that you can use systemctl start|stop|restart dietpi-autostart_custom to handle it, same as all other systemd services. Systemd units by default run non-interactively in background, so they are not attached to the terminal and you cannot interrupt them e.g. via ctrl+c.
  • Otherwise, if you e.g. want a script to start at login, use /etc/profile.d/my_script.sh, which will then start interactively (in foreground) on terminal, thus can be interrupted.
  • You can also add some conditional exit path for your script code, but depends on what it does and how ๐Ÿ˜‰.

Will mark as closed, since question has been answered/issue solved. Feel free to reopen, if required.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

oshank picture oshank  ยท  3Comments

Fourdee picture Fourdee  ยท  3Comments

pgferr picture pgferr  ยท  3Comments

k-plan picture k-plan  ยท  3Comments

pfeerick picture pfeerick  ยท  3Comments