In some circumstances, ltcluster (and ltclusterd) need to
be able to stop, start or restart LightDB. ltcluster commands which need to do this
include ltcluster standby follow
,
ltcluster standby switchover
and
ltcluster node rejoin
.
By default, ltcluster will use LightDB's lt_ctl
utility to control the LightDB
server. However this can lead to various problems, particularly when LightDB has been
installed from packages, and especially so if systemd is in use.
With this in mind, we recommend to always configure ltcluster to use the available system service commands.
To do this, specify the appropriate command for each action
in ltcluster.conf
using the following configuration
parameters:
service_start_command service_stop_command service_restart_command service_reload_command
ltcluster will not apply pg_bindir
when executing any of these commands;
these can be user-defined scripts so must always be specified with the full path.
It's also possible to specify a service_promote_command
.
This is intended for systems which provide a package-level promote command,
such as Debian's pg_ctlcluster, to promote the
LightDB from standby to primary.
If your packaging system does not provide such a command, it can be left empty, and ltcluster will generate the appropriate `lt_ctl ... promote` command.
Do not confuse this with promote_command
, which is used
by ltclusterd to execute ltcluster standby promote.
To confirm which command ltcluster will execute for each action, use
ltcluster node service --list-actions --action=...
, e.g.:
ltcluster -f /etc/ltcluster.conf node service --list-actions --action=stop ltcluster -f /etc/ltcluster.conf node service --list-actions --action=start ltcluster -f /etc/ltcluster.conf node service --list-actions --action=restart ltcluster -f /etc/ltcluster.conf node service --list-actions --action=reload
These commands will be executed by the system user which ltcluster runs as (usually lightdb
)
and will probably require passwordless sudo access to be able to execute the command.
For example, using systemd on CentOS 7, the service commands can be set as follows:
service_start_command = 'sudo systemctl start lightdb-9.6' service_stop_command = 'sudo systemctl stop lightdb-9.6' service_restart_command = 'sudo systemctl restart lightdb-9.6' service_reload_command = 'sudo systemctl reload lightdb-9.6'
and /etc/sudoers
should be set as follows:
Defaults:lightdb !requiretty lightdb ALL = NOPASSWD: /usr/bin/systemctl stop lightdb-9.6, \ /usr/bin/systemctl start lightdb-9.6, \ /usr/bin/systemctl restart lightdb-9.6, \ /usr/bin/systemctl reload lightdb-9.6
Debian/Ubuntu users: instead of calling sudo systemctl
directly, use
sudo pg_ctlcluster
, e.g.:
service_start_command = 'sudo pg_ctlcluster 9.6 main start' service_stop_command = 'sudo pg_ctlcluster 9.6 main stop' service_restart_command = 'sudo pg_ctlcluster 9.6 main restart' service_reload_command = 'sudo pg_ctlcluster 9.6 main reload'
and set /etc/sudoers
accordingly.
While pg_ctlcluster
will work when executed as user lightdb
,
it's strongly recommended to use sudo pg_ctlcluster
on systemd
systems, to ensure systemd has a correct picture of
the LightDB application state.