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

Changes to point the systemd services file to /etc/default/caddy #55

Closed
wants to merge 1 commit into from
Closed

Conversation

hvisage
Copy link

@hvisage hvisage commented Feb 24, 2021

This is a "simple" method to not mess with the systemd services file but to allow the sysadmin to use the /etc/default/caddy to point to a different (especially .json) config file and EXTRA_PARAMS support for --resume (or --watch etc.)

I know there is a "new recommended" method to make use of systemctl edit as mentioned here but that is not what I'm "ised" to, and the /etc/default/caddy is easier to ansible lineinfile edit

@francislavoie
Copy link
Member

francislavoie commented Feb 24, 2021

I don't think that's a good idea. --resume doesn't really make sense to be paired with a Caddyfile; you'll get unexpected behaviour because the autosaved config will take precedence over any changes made to your file specified in --config. This was a well-debated topic.

I realize you're making this opt-in, but I think this muddies the water. I'd rather people use systemctl edit instead if they need to deviate from either service file.

@hvisage
Copy link
Author

hvisage commented Feb 24, 2021

  1. --resume okay, what about I remove references for that? (EXTRA_PARAMS can still be used without it for other options)

  2. how do you automate/script systemctl edit from Ansible/etc. ? It only opens a blank file, meant for Environment variables from the tests I've done on systemctl edit caddy & systemctl edit caddy.service on the Debian where I did installed via the packages

The issue here: I want to point to a different --configfile (Specifically json that was autogenerated from elsewhere), several services use /etc/default/<service_name> to have it dynamically point to other config files without messing with the services/unit files. Files like /etc/default/caddy is typically marked as "volatile/user-edited" where as /lib/systemd/system/caddy.service is typically frowned upon to edit as the package managers should warn when those changed with out updates to the packages databases

@francislavoie
Copy link
Member

See https://www.digitalocean.com/community/tutorials/how-to-use-systemctl-to-manage-systemd-services-and-units#editing-unit-files for an explanation of how it works. You don't need to use edit if you're automating, you just drop the file in the right place as described there.

@carlwgeorge
Copy link
Collaborator

I agree with @francislavoie, systemd has a robust and easy to use override system with multiple options for customizing unit files. There isn't a compelling reason to do something non-standard here. I'm -1 on this pull request.

As far as ansible goes, I think it's much easier to write a new drop-in file with the copy module than it is to modify an existing file with the lineinfile module. Anytime I can avoid writing regex I will. Here's an example.

- name: override caddy unit file
  copy:
    dest: /etc/systemd/system/caddy.service.d/custom.conf
    contents: |
      [Service]
      ExecStart=
      ExecStart=/usr/bin/caddy run --environ --config /opt/Caddyfile
      ExecReload=
      ExecReload=/usr/bin/caddy reload --config /opt/Caddyfile

The empty directives aren't a typo, they are necessary when overriding because a unit file can have multiple of those directives, so you have to "clear" the directive from the stock file.

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.

3 participants