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
  • Atherel@lemmy.dbzer0.com
    link
    fedilink
    English
    arrow-up
    1
    ·
    8 hours 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.

  • Shadow@lemmy.ca
    link
    fedilink
    English
    arrow-up
    8
    ·
    13 hours ago

    If you want to be lazy, use crontab @reboot

    Making a systemd unit is the “correct” way

    • helloworld@lemmy.mlOP
      link
      fedilink
      English
      arrow-up
      5
      ·
      edit-2
      13 hours ago

      Yeah after searching on the arch wiki, I guess systemd timers, not services, are specifically what I was interested in, thanks!

  • Possibly linux@lemmy.zipM
    link
    fedilink
    English
    arrow-up
    2
    ·
    edit-2
    12 hours ago

    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.

    • helloworld@lemmy.mlOP
      link
      fedilink
      English
      arrow-up
      1
      ·
      12 hours ago

      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.

      • Possibly linux@lemmy.zipM
        link
        fedilink
        English
        arrow-up
        2
        ·
        12 hours 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.

  • helloworld@lemmy.mlOP
    link
    fedilink
    English
    arrow-up
    5
    ·
    edit-2
    15 hours 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.

  • aubeynarf@lemmynsfw.com
    link
    fedilink
    English
    arrow-up
    2
    ·
    15 hours ago

    In general, the kernel starts one program after it finishes booting, and that process starts everything else; traditionally it’s called ‘init’. systemd is a “modern” replacement.

    Different distributions and unix variants use different “init” patterns and tooling; so find out what your distribution is using.

    Those patterns are designed for this use case but you need to understand the different phases of startup and where your script should fit in.

    What distro are you using?