this post was submitted on 25 Aug 2025
8 points (100.0% liked)

Linux Questions

2485 readers
50 users here now

Linux questions Rules (in addition of the Lemmy.zip rules)

Tips for giving and receiving help

Any rule violations will result in disciplinary actions

founded 2 years ago
MODERATORS
 

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 8 comments
sorted by: hot top controversial new old
[–] Shadow@lemmy.ca 8 points 17 hours ago (1 children)

If you want to be lazy, use crontab @reboot

Making a systemd unit is the "correct" way

[–] helloworld@lemmy.ml 5 points 17 hours ago* (last edited 17 hours ago)

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

[–] Atherel@lemmy.dbzer0.com 1 points 11 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.

[–] helloworld@lemmy.ml 5 points 19 hours ago* (last edited 19 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.

[–] possiblylinux127@lemmy.zip 2 points 16 hours ago* (last edited 16 hours ago) (1 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.

[–] helloworld@lemmy.ml 1 points 15 hours ago (1 children)

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.

[–] possiblylinux127@lemmy.zip 2 points 15 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.

[–] aubeynarf@lemmynsfw.com 2 points 18 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?