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

Use /etc/default/ to source configuration for Canto init script #2476

Closed
jseager7 opened this issue Jun 21, 2021 · 3 comments · May be fixed by #2478
Closed

Use /etc/default/ to source configuration for Canto init script #2476

jseager7 opened this issue Jun 21, 2021 · 3 comments · May be fixed by #2478

Comments

@jseager7
Copy link
Collaborator

I've been trying out the example init script for Canto, and I think it's a bit peculiar how the actual init script file (link) doesn't do anything except run another script file that does all the work (link).

The only reasons I can see for this approach are:

  1. To allow the script to be run as root, although presumably if the script was run through init.d then the script would be run as root anyway, or at least with sufficient priveleges; and

  2. To fix additional arguments, like the port number for Canto.

I investigated how other init scripts solve the problem of additional configuration, and it seems the conventional approach is to add a file in /etc/default/ containing variables that are then sourced into the main script file. Personally, I'd prefer to have only one init script which sets default values, and keep the configuration overrides in a separate file.

The existing init scripts I've looked at have competing approaches to how they check the validity of their configuration files, but they're broadly equivalent. Some examples are shown below:

cron

-r: True if file exists and is readable.

[ -r /etc/default/cron ] && . /etc/default/cron

D-Bus

-e: True if file exists.

if [ -e /etc/default/dbus ]; then
    . /etc/default/dbus
fi

Docker

-f: True if file exists and is a regular file.

if [ -f /etc/default/$BASE ]; then
    . /etc/default/$BASE
fi

Based on the init script for Docker, it seems any variables sourced from the file in /etc/default/ will override the variables in the main script, so the script can declare default values and then override them if a default file exists: there's no need to put the default declarations in an else block. The variables are left commented out in the configuration file, and presumably it's up to the user not to override the default values with empty values by accident.

These are the following variables that I think should be configurable:

  • WORKERS: maximum number of workers for Server::Starter; it would be useful to allow this to be lowered for development setups that could be more memory-constrained.
  • port: the port number for connections to Canto.
  • CANTO_SPACE: the directory for Canto's source files; this is mainly important for my development setup, since that doesn't use the same directory as our servers.
  • PID_PATH: this probably matters less, since I think it only applies to the Docker container, but it might be useful to someone if it were configurable.

Note that systemd seems to use a different approach to overriding configuration (see docs), so it's worth being aware of that in case any Canto user decides to migrate to systemd in future. We might want to document the configuration override process for both service managers (SysV style and systemd style).

@kimrutherford are you happy with this approach? Are there any compelling reasons to stay with the current approach? I'm happy to take care of making the changes, testing them, and updating the documentation. I realise that FlyCanto might already be using the existing system, so I'll have to take care that any changes don't inconvenience them.

@kimrutherford
Copy link
Member

I've been trying out the example init script for Canto, and I think it's a bit peculiar how the actual init script file doesn't do anything except run another script file that does all the work.

Sorry, you're right, that is a bit unnecessary. It was a quick adaption of our actual scripts. We have an init.d script for each instance of Canto. I took one of them and hard coded things. Our scripts look like the example below, but the "pombe" and the port change depending on the instance. ("pomcur" is the account we use for running Canto)

This is /etc/init.d/canto-pombe:

#!/bin/sh -

#
### BEGIN INIT INFO
# Provides:          canto-pombe
# Required-Start:    $remote_fs $syslog
# Required-Stop:     $remote_fs $syslog
# Should-Start:
# Should-Stop:
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: canto pombe
### END INIT INFO
#

su -c "/sbin/canto-initd pombe $* 7000" pomcur  &

Our canto-initd script is a bit different too: https://github.com/pombase/canto/blob/b4ae34379a6942be9c6dff4dd7ce9d2281f76a82/etc/canto-ctlr

@kimrutherford are you happy with this approach? Are there any compelling reasons to stay with the current approach? I'm happy to take care of making the changes, testing them, and updating the documentation.

Yep, that sounds great.

@ValWood
Copy link
Member

ValWood commented Nov 29, 2023

Reopen if there is still an action, but it seems solved?

@ValWood ValWood closed this as completed Nov 29, 2023
@jseager7
Copy link
Collaborator Author

I'll close this as not planned since I doubt I'll ever get round to it.

@jseager7 jseager7 closed this as not planned Won't fix, can't repro, duplicate, stale Nov 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants