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

Place systemd units in /usr/lib/systemd/system #260

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

behrmann
Copy link

@behrmann behrmann commented Feb 15, 2021

Using /usr/lib/systemd/system allows local sysadmins to overwrite the unit file by placing one of the same name in /etc/systemd/system.

Fixes: #259

@coveralls
Copy link

coveralls commented Feb 15, 2021

Coverage Status

Coverage decreased (-0.03%) to 12.733% when pulling e8fc22a on behrmann:unitseachpath into a8dda22 on kardianos:master.

@behrmann
Copy link
Author

Just noticed, that in the meantime a merge conflict has occurred, so I rebased against current master.

@kardianos
Copy link
Owner

Thanks. Also, this is a fine change, but for some operations, we need to check both the old and new path in sequence to not break existing programs.

@behrmann
Copy link
Author

Which operations do you have in mind?

When writing a new file to /usr/lib instead of /etc the latter will take precedence and as long as how the service is to be invoked it will keep in working. In most cases the same file will be recreated in /usr/lib. Sure, as long as there is a file in /etc all newly generated files won't take effect, but I don't think that is something this module can do something about, because the only way out is deleting that and that's generally not a good idea, because it could be a user-edited/user-supplied file.

I could imagine writing a warning when a service file is generated, that is shadowed by one in /etc.

@kardianos
Copy link
Owner

  1. Please reference documentation as to the different locations.
  2. For checking existence or for removal, both locations should be checked.
  3. For creating a new service instance, only the new location should be used.

@behrmann
Copy link
Author

1. Please reference documentation as to the different locations.

Where exactly should I reference documentation?

2. For checking existence or for removal, both locations should be checked.

I'm not sure I agree.

Removing files under /etc is just not a good idea. This module should never touch /etc. Managing files under /etc is the prerogative of the user/sysadmin or at the least the package manger, but daemons shouldn't touch it, since the risk of inadvertently deleting a file the user doesn't want to lose is too high.

Checking for existence of a file under /etc for the installation shouldn't really matter all that much, since it will generally mean that a user supplied their own service file. Supplying a vendor service file in /usr/lib still makes sense, so it might be prudent to just get rid of the check

    _, err = os.Stat(confPath)
    if err == nil {
        return fmt.Errorf("Init already exists: %s", confPath)
    }

in Install and always clobber the file under /usr/lib.

3. For creating a new service instance, only the new location should be used.

Ok, I think that would be the case of the PR in its current state

@kardianos
Copy link
Owner

  1. Just add a comment near the referenced /usr/lib location.
  2. Well, we are writing and removing now. So we need to continue looking for files there, at least for now, or bump to v2, and I don't think I want to bump to v2. We can add an option to opt out of looking at etc, so a new author can opt to use that.

@behrmann
Copy link
Author

behrmann commented Jun 10, 2021

  1. Just add a comment near the referenced /usr/lib location.

Done.

  1. Well, we are writing and removing now. So we need to continue looking for files there, at least for now, or bump to v2, and I don't think I want to bump to v2. We can add an option to opt out of looking at etc, so a new author can opt to use that.

That doesn't make it a good idea. Example: A binary I use currently uses this module and places its service file in /etc. The point of this PR is to not have to replace that file all the time anymore. If that binary now started removing that very same file again would make this change a bit pointless. :)

I consider writing to /etc a bug. The proper state of a service file under /etc is unknowable from the point of this module and I think it is definitely better to be safe and not to guess.

Using /usr/lib/systemd/system allows local sysadmins to overwrite to unit file
by placing one of the same name in /etc/systemd/system.

Fixes: kardianos#259
@gregharvey
Copy link

Cross-posting discussion in the GitLab issue queue:

As a gitlab-runner user this is pretty frustrating - every time they push an upgrade everyone with custom overrides finds their runners break until they fix the unit file. What do we need to do to get this over the line? Can I help? I've never really used Go, but I don't mind having a crack if there's a spec the maintainer would be happy with. 😄

@gregharvey
Copy link

For anyone who finds this while the PR is in limbo, workarounds are possible - see use of override configs in https://askubuntu.com/a/659268

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Install systemd service files to /usr/lib/systemd/system so that they can be overwritten
4 participants