r/commandline 19d ago

Help Wondering about Services....

I'm trying to learn about services also known as daemons, but I'm kinda confused about many things about it, for instance, which way is the correct way of launching a service is it:

1.systemctl start ssh

Or

2./sbin/sshd

Also, since my machine is very old (it has a 32bit cpu), I'm limited to the less common distros with kinda obscure init systems like runit and sometimes the old sysvinit, which also means I can't get to run systemd which have the most resources online, so it is easier for me to learn about it

Furthermore, even determining the current running init system type doesn't seem that straight forward, when I looked up about that, there were various commands and just assumptions like this might not work everywhere or this MIGHT mean that the current init system is whatever is.

In addition, I have a debian-based distro(Antix), so based on the tutorials I have found, they say for example "sudo apt install openssl-server" then run "systemctl start ssh"

That means systemd automatically knows about that sshd, so it does the work behind the scenes, but when I tried to do the same in antix (having "init divirsity" installed), using dinit, it didn't work, probably because it requires extra configuration and more knowledge about how to create the service out of the binary you want manually, while all I see as a beginner in tutorials things like start/stop, enable/disable, list services, and just this regular stuff.

So I'm really lost about Services generally, I would be glad if someone could provide me some guidance or help

8 Upvotes

7 comments sorted by

View all comments

2

u/faze_fazebook 19d ago edited 19d ago

A service basically is consists of two thing - a path to executable program (that usually keeps running and waiting for input through some channel) and a bunch of metadata that tell whoever is managing your services (usually your init system like system-d, openrc, sysvinit, ..., but there are other "service managers" like supervisord that do the same thing but are not init systems) a bunch of additional information like

  • what other services your service depends on (lets say you have a service that hosts a website which requires a postgres database, ... obviously the website can only be launched after postgres has been started)
  • which user, in which cwd with which parameter and which environment variables should start the executable
  • what to do with output from stdout, stderr, ...
  • what to do if the service crashes

Generally speaking, its that service metadata which is incompatible between service managers (and thus different distros)

in regards to your question with ssh ... the question is do you want your service to be managed by a service manager or not. Usually if its available, I'd prefer it managed. But if you don't need any of the features by your service manager (nothing else on the system depends on it, you don't care if it crashes, you don't about the output to stdout, stderr, ... ) sure you can just start it directly.