Skip to content
This repository was archived by the owner on Jun 24, 2022. It is now read-only.

Support for service alias with systemd. (enhancement) #336

Closed
mapo-job opened this issue Jul 18, 2017 · 9 comments
Closed

Support for service alias with systemd. (enhancement) #336

mapo-job opened this issue Jul 18, 2017 · 9 comments

Comments

@mapo-job
Copy link

Would like the possibility to add an alias in systems script.
This is using a new variable es_service_alias.
Update templates/systemd/elasticsearch.j2, add at the end after WantedBy line:

{% if es_service_alias is defined %}
Alias={{es_service_alias}}.service
{% endif %}

Reason: the current implementation does
- set_fact: instance_init_script={{init_script | dirname }}/{{es_instance_name}}_{{init_script | basename}}
and the service name is nodeName_elasticsearch.service
I want to use the service name elasticsearch instead.

@gingerwizard
Copy link

@barryib @jakommo whilst this doesn't quite align with our "package files must be consistent with upstream changes" this is actually potentially really useful. Any objections?

@barryib
Copy link
Contributor

barryib commented Aug 19, 2017

I thinks it's a part of #354 discussion.

@jpcarey
Copy link
Contributor

jpcarey commented Aug 20, 2017

Although this seems to be very useful, I'd be against allowing further customizations to the unit file that elastic provides (in the spirit of #285). Systemd encourages use of override files, which could be utilized for adding any customizations to the original vendor unit.

systemctl edit elasticsearch.service would create a directory in /etc/systemd/system named after the unit, and an override.conf file in that directory (/etc/systemd/system/elasticsearch.service.d/override.conf)

@gingerwizard
Copy link

Several options:

  1. We use @jpcarey approach. Possibly we allow the user to provide an override file.
  2. Is there a reason why set_fact: is used instead of vars/main.yml? #133 suggests exposing the init/systemd names as variables rather than setting them as facts. Users could then override them. If they don't ensure they are unique this could cause issues with multiple instances on a single host - we'd need to document as i see no easy way to check and validate this (mind you they could easily set instance_name as non unique also).

Thoughts? @jpcarey @barryib @mapo-job

@mapo-job
Copy link
Author

I agree that override is a better solution but it did not work for me.
I’m doing the installation and this new variable is not part of the default usage.
So if someone set it, I hope it’s because they read the comment that says it’s for single node per machine.

On CentOS 7 I try to use the override but it did not work.

sudo systemctl edit nodename_elasticsearch.service

#Add content:
[Install]
Alias=
Alias=elasticsearch.service

ls -la /etc/systemd/system/nodename_elasticsearch.service.d/override.conf

-rw-r--r--. 1 root root 45 Aug 22 14:22 /etc/systemd/system/nodename_elasticsearch.service.d/override.conf

sudo systemctl status elasticsearch

Unit elasticsearch.service could not be found.

sudo systemctl daemon-reload
sudo systemctl status elasticsearch

Unit elasticsearch.service could not be found.

sudo systemctl reenable nodename _elasticsearch.service
sudo systemctl status elasticsearch

Unit elasticsearch.service could not be found.

@strootman
Copy link
Contributor

To get around this, I set up my ansible inventory as follows (the names have been changed to protect the innocent);

[elasticsearch-nodes]
hot-1 ansible_host=es1.internet.com
client-1 ansible_host=es1.internet.com
hot-2 ansible_host=es2.internet.com
client-2 ansible_host=es2.internet.com

Next, I override the following variables as follows;

es_instance_name: "{{inventory_hostname_short}}"
instance_suffix: "{{es_instance_name}}"

I'm glazing over a lot of the details, but this is how I use this role to provide multi-node installation/administration. This also bypasses the need to run multiple playbooks for a single host.

@jpcarey
Copy link
Contributor

jpcarey commented Sep 22, 2017

@mapo-job ah, [Install] can't be used in an override conf, more details on why here: systemd/systemd#1090

The workaround that I found in that issue is to just create the symlink in /etc/systemd/system:

[vagrant@localhost ~]$ sudo ln -s /usr/lib/systemd/system/elasticsearch.service /etc/systemd/system/es.service
[vagrant@localhost ~]$ systemctl status es.service
● elasticsearch.service - Elasticsearch
   Loaded: loaded (/usr/lib/systemd/system/elasticsearch.service; enabled; vendor preset: disabled)
  Drop-In: /etc/systemd/system/elasticsearch.service.d
           └─override.conf
   Active: inactive (dead)
     Docs: http://www.elastic.co

Hope that helps!

@jmlrt
Copy link
Member

jmlrt commented May 29, 2019

Hi @mapo-job,
This should be fixed by #566 very soon.

@jmlrt
Copy link
Member

jmlrt commented Jul 12, 2019

#566 is merged.
I'm closing the issue, don't hesitate to reopen it if you have any question.

@jmlrt jmlrt closed this as completed Jul 12, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants