46
submitted 4 months ago by Fatur0000@lemmy.ml to c/linux@lemmy.ml

Why do they use Shell?

Sorry for bad English. English isn't my native languange

top 11 comments
sorted by: hot top controversial new old
[-] JWBananas@lemmy.world 39 points 4 months ago

The script-based systems came first. They had to evolve into the amalgamation of pitfalls that they have become for someone to abstract out their important concepts into something that could use configuration files.

[-] stsquad@lemmy.ml 31 points 4 months ago

While shell based RC systems do offer flexibility they also have downsides including copy and paste leading to subtly different behaviour across units. Dependency resolution was also a bit of a hack on top of scripts to deal with concepts like run levels.

The declarative approach of a proper configuration is a better and more scalable solution.

[-] dsemy@lemm.ee 11 points 4 months ago

they also have downsides including copy and paste leading to subtly different behaviour across units

What does this mean? How is an imperative shell scripts doing something subtly different? Why won't a declarative config file do the same?

Dependency resolution was also a bit of a hack on top of scripts to deal with concepts like run levels.

Runlevels don't really have anything to do with dependency resolution though?

The declarative approach of a proper configuration is a better and more scalable solution.

Maybe it is, but you didn't explain why.

[-] chalk46@fedia.io 4 points 4 months ago* (last edited 4 months ago)

in systemd runlevels are basically just targets (it still sets rc?.d symlinks in /etc akaik) which have services they want and are wanted by, it's the basis for dependency handling plus you get cool security features like syscall filtering, capability limits, user switching, etc

[-] dsemy@lemm.ee 2 points 4 months ago

Well in Void (using runit) each runlevel is just a directory with symlinks to the services.

I didn't realize systemd had these security features (except for user/group switching, which is pretty standard). You can get those with other init systems, but it's probably easier on systemd so I assume more people actually do it. I wonder if average distros take the time to harden their unit files.

[-] stsquad@lemmy.ml 3 points 4 months ago

You can end up with a lot of boiler plate code and with duplication you run the risk that one unit tweaks the boiler plate in a way that behaves differently. This isn't insurmountable and a lot of rc scripts source a library of common functions shared between units. However from the point of view of the executor each unit is it's own whole ball of shell script code.

[-] dsemy@lemm.ee 8 points 4 months ago

Most service scripts on my machine (Void with runit) are less than 10 lines long, and don't contain any "boiler plate" other than a shebang.

[-] TootSweet@lemmy.world 16 points 4 months ago

I think in *nix, shell-configured init systems came first and the non-shell config file init systems are a more recent development. The real question is why the non-shell-configured init systems decided to change it up.

[-] PumpkinEscobar@lemmy.world 14 points 4 months ago

I'm far from an expert in init systems, but there are some benefits to declarative approaches for configuration. It's one of the main reasons yaml and toml are as popular as they are. The short version is, declarative configuration tends to be less verbose, and the declarative contract defines what state you want things to be in, not how to get there which makes it easier on the person writing the unit file, and on the implementers of systemd in that there's a smaller surface-area to test

Generally declarative:

  • requires less verbose configuration files, less room for error
  • is easier to document and easier to understand
  • leaves the implementers more freedom to improve their system as long as they live up to the agreed-upon contract
  • is easier for implementers to test/validate. They don't need to support a scripting language and every single crazy thing someone might try with one but still consider valid
[-] stsquad@lemmy.ml 4 points 4 months ago

The declarative approach also allows for better composability - user tweaks can just be the relevant lines on top of the packaged default config.

[-] ryannathans@aussie.zone 5 points 4 months ago

Shell scripts work well for simple portable programmability

this post was submitted on 26 Mar 2024
46 points (92.6% liked)

Linux

46643 readers
775 users here now

From Wikipedia, the free encyclopedia

Linux is a family of open source Unix-like operating systems based on the Linux kernel, an operating system kernel first released on September 17, 1991 by Linus Torvalds. Linux is typically packaged in a Linux distribution (or distro for short).

Distributions include the Linux kernel and supporting system software and libraries, many of which are provided by the GNU Project. Many Linux distributions use the word "Linux" in their name, but the Free Software Foundation uses the name GNU/Linux to emphasize the importance of GNU software, causing some controversy.

Rules

Related Communities

Community icon by Alpár-Etele Méder, licensed under CC BY 3.0

founded 5 years ago
MODERATORS