I think there are multiple things one could do to achieve this, but am uncertain which way to go:

  • if you use systemd create a systemd service I guess? How to create systemd service that runs a (python) script on startup?
  • some files similar to .bashrc always run on system startup/boot?; use this if you are less fancy / have no systemd

top 7 comments

sorted by: hot top controversial new old
[–] 8 points 1 year ago (1 child)

If you want to be lazy, use crontab @reboot

Making a systemd unit is the "correct" way

  • source
  • hideshow 1 child comment
  • [–] [S] 5 points 1 year ago* (last edited 1 year ago)

    meta: I know such questions have been asked before on stackoverflow; but lets bring them to fediverse as well (I hate stackoverflow web-design, google pop-ups, and javascript). I noticed there are always multiple ways to do such things in Linux. I think some options are very popular, while others go unmentioned (by LLMs for example). Also on different linux distributions there are different options available as far as I understand.

  • source
  • [–] 2 points 1 year ago* (2 children)

    What do you want to accomplish? Systemd can do lots of things like monitoring, sandboxing and dependency management along with just running commands.

    If you are on a Busybox init based system like OpenWRT you can also just write a init script.

  • source
  • hideshow 2 child comments
  • [–] [S] 1 point 1 year ago (1 child)

    My first simple use case: I want to start a http (busybox httpd) server on localhost inside a certain directory whenever I turn the PC on.

  • source
  • parent
  • hideshow 1 child comment
  • [–] 2 points 1 year ago

    Don't use a script for this

    I would setup Lighttpd since it is a proper server while being pretty lightweight. It should come with the needed systemd unit so that you can just do sudo systemctl start lighttpd

    Avoid writing scripts like the plague. Config files are much better and will scale better.

  • source
  • parent
  • [–] 1 point 1 year ago

    If it's a service, best to use systemd or your OSs equivalent. If that's not possible, the @boot cronjob was already mentioned.

    Also maybe look at supervisord or s6.

  • source