Closed harvey637 closed 4 months ago
also please fix the daemon-reload and the enabling of the service:
- name: restart postgresql
service:
name: "{{ postgresql_service_name }}"
state: restarted
daemon_reload: yes
enabled: "{{ postgresql_service_enabled }}"
@harvey637 , is this similar to #289 ? That gives service names such as:
postgresql-11-clustername
This allows you name your cluster, and have unique services just in case you want multiple clusters on the one server. I did this without having to mess with the main service file, by including it:
# {{ ansible_managed }}
# Systemd unit file override to specify user/group as well as separate config
# and data directories.
.include /lib/systemd/system/postgresql-{{ postgresql_version }}.service
[Unit]
Description=PostgreSQL {{ postgresql_version }} database server - cluster_name:{{ postgresql_cluster_name }}
[Service]
User={{ postgresql_service_user }}
Group={{ postgresql_service_group }}
Environment=PGDATA={{ postgresql_conf_directory }}
{% if postgresql_version is version_compare('10', '>=') %}
ExecStartPre={{ postgresql_bin_directory }}/postgresql-{{ postgresql_version_terse }}-check-db-dir {{ postgresql_data_directory }}
{% else %}
ExecStartPre={{ postgresql_bin_directory }}/postgresql{{ postgresql_version_terse }}-check-db-dir {{ postgresql_data_directory }}
{% endif %}
Hi, similar, but not fully customizable. I dont want the part "postgresql-11". I use something like "sonar-db" with the "sonar-" part as indication of the application this database is for. So from a higher level I start/restart/status "sonar-db" for the sonar-database and "sonar" for the applikation. On the same system I might have a "bacula-db" and "bacula"-application. As you can see my systemd-unit very similar to yours as I also use the ".include" of the original postgresql-database systemd-unit, but with a "free variable" as service name.
So my proposal looks universal to me, as the servicename is any variable (might default to "postgresql-{{ pgversion }}" ) cu Harvey
also please fix the daemon-reload and the enabling of the service:
- name: restart postgresql service: name: "{{ postgresql_service_name }}" state: restarted daemon_reload: yes enabled: "{{ postgresql_service_enabled }}"
I think this possible only witth systemd module. I propose another solution: #443. Service restarts should be done with service module so we have only one restart task for all distros. And distros with systemd should have systemd reload before restart.
This issue has been marked 'stale' due to lack of recent activity. If there is no further activity, the issue will be closed in another 30 days. Thank you for your contribution!
This issue has been closed due to inactivity. If you feel this is in error, please reopen the issue or file a new issue with the relevant details.
Hi sometimes I use a postgresdatabase and want to give it a easy name to control it, e.g. "holiday-db". Then I can "systemctl start|status|stop holiday-db". I dont care about the version of postgresql in the servicename.
To achive this I modified:
and than in
Than I can override the var _postgresql_servicename and create my custom serviceunit for this.
In the end I have either two tasks creating custom_conf directory and file OR my own serviceunit. I could also use a template for my own serviceunit. cu Harvey