Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support of non systemd linux systems. #487

Open
zen2 opened this issue Nov 7, 2024 · 2 comments
Open

Support of non systemd linux systems. #487

zen2 opened this issue Nov 7, 2024 · 2 comments
Labels
enhancement New feature or request

Comments

@zen2
Copy link

zen2 commented Nov 7, 2024

My system is not using systemd and so NSL is not launched as a daemon and produce errors when looking for systemctl command.
I've commented systemd part of the code and I'm able to install launchers.
I can scan games too by using myNSLGameScanner.py but I need to restart steam in order to see new games (I don't know if this restart is required on functional NSL installation).

So it can be really good to detect other classical /etc/init.d system and ideally to have a script that accept start/stop/restart in order that NSL can be easily integrated in any kind of init system.

@moraroy
Copy link
Owner

moraroy commented Nov 8, 2024

@zen2 ah thanks for the heads up, I didn't realize that would be an issue! I'll try my best to fix that for you, so essentially since there is no service file being ran, you're basically just running the .py manually correct? If I can find a way to not have a service file that would be better in my opinion.

@zen2
Copy link
Author

zen2 commented Nov 8, 2024

@moraroy the classical way is to make a script autonomous from system with optionally a background option command and provide optionality systemd or init.d files separately. In my case I can write my own init.d one if the script works on itself.

Most of linux distro package maintainers write needed init.d script or systemd init files to launch daemon process.
So it means your script have to be independent from it.
It is the init system that take care to start/stop/restart and keep it in background the process/script.
Usually the init system create a pid file to track if the process have been already start and is running.
Note that the process can create his own pid file on his own if needed and so the init.d system will use it.

About background option:
It means when you launch the script normally from a terminal it will be launched in foreground by taking over the terminal and use it for stdout/stderr.
With an option like --background/-b the script can detach from terminal and run in background.

About daemon exit:
If you need to clean up some temporary files or execute specific actions before the daemon exits you need to intercept signals that will be send by the init system to kill the daemon. Usually init system send a SIGTERM signal to ask daemon to terminate properly then a SIGKILL signal to kill it anyway after a timeout in case the process doesn't terminate.

Basic example in bash:

#!/bin/bash

myname="$(basename $0)"
mypath="$(dirname $0)"
mylog="/tmp/${myname}.log"

# Relaunch script in background and exit
if [ "$1" = "-b" ]; then
  nohup "$mypath/$myname" &> "$mylog" &
  pid=$!
  echo "$myname is running now in background."
  echo "Command to terminate the background process: kill -15 $pid"
  exit 0
else
  echo "Launch me with -b option to make me running in background."
fi

# function to clean up before exiting
exit_on_trap() {
  echo "Execute actions to clean up before exiting"
  rm "$mylog"
  exit 0
}

# intercept exit signal to exit properly
trap exit_on_trap SIGTERM SIGQUIT

# Daemon main loop
while true; do
  sleep 1
  echo "I'm alive"
done

In python, take a look to:

@moraroy moraroy added the enhancement New feature or request label Dec 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants