Skip to content

Instantly share code, notes, and snippets.

@huehnerhose
Last active January 3, 2024 16:51
Show Gist options
  • Save huehnerhose/72de62dc808fd79034497772a7ef7e0f to your computer and use it in GitHub Desktop.
Save huehnerhose/72de62dc808fd79034497772a7ef7e0f to your computer and use it in GitHub Desktop.
patroni FreeBSD rc.d script
#!/bin/sh
# PROVIDE: PATRONI
# REQUIRE: ETCD
# BEFORE: LOGIN
# KEYWORD: shutdown
# https://www.dbi-services.com/blog/patroni-on-freebsd-13/
. /etc/rc.subr
name="patroni"
rcvar=patroni_enable
start_cmd="patroni_start"
reload_cmd="${name}_reload"
list_cmd="${name}_list"
history_cmd="${name}_history"
extra_commands="list history"
su_cmd="/usr/bin/su"
daemon_cmd="/usr/sbin/daemon"
kill_cmd="/bin/kill"
sudo_cmd="/usr/local/bin/sudo"
pidfile="/var/run/${name}.pid"
patroni_start()
{
# -S -> syslog output
# -R 10 restart after 10s when patroni died
# -P daemon pidfile
# -T syslog Tag
echo "Start ${name}"
${daemon_cmd} -S -R 10 -u ${patroni_user} --child-pidfile ${pidfile} -T ${name} ${patroni_cmd} ${patroni_config}
}
patroni_reload()
{
${sudo_cmd} -u ${patroni_user} ${patroni_ctl} -c ${patroni_config} reload
}
patroni_list()
{
${sudo_cmd} -u ${patroni_user} ${patroni_ctl} -c ${patroni_config} list
}
patroni_history()
{
${sudo_cmd} -u ${patroni_user} ${patroni_ctl} -c ${patroni_config} history
}
load_rc_config $name
: ${patroni_user="postgres"}
: ${patroni_config="/usr/local/etc/patroni.yml"}
: ${patroni_bin_root="`eval echo ~${patroni_user}`/.local/bin"}
: ${patroni_cmd:="${patroni_bin_root}/patroni"}
: ${patroni_ctl:="${patroni_bin_root}/patronictl"}
run_rc_command "$1"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment