#!/bin/sh # PROVIDE: lightningd # REQUIRE: LOGIN bitcoind cleanvar # KEYWORD: shutdown # Add the following to %%LOCALBASE%%/etc/rc.conf.d/lightningd to influence # the behavior of this script (default values are listed): # # lightningd_enable="NO" # change to "YES" to enable # lightningd_user="%%U%%" # lightningd_group="%%G%%" # lightningd_base_dir="%%LIGHTNINGD_BASE_DIR%%" # lightningd_network="bitcoin" # lightningd_conf="%%PREFIX%%/etc/lightningd-${lightningd_network}.conf" # lightningd_extra_args="" # See lightningd --help . /etc/rc.subr name="lightningd" rcvar=lightningd_enable load_rc_config ${name} : ${lightningd_enable:="NO"} : ${lightningd_user:="%%U%%"} : ${lightningd_group:="%%G%%"} : ${lightningd_base_dir:="%%LIGHTNINGD_BASE_DIR%%"} : ${lightningd_network:="bitcoin"} : ${lightningd_conf:="%%PREFIX%%/etc/${name}-${lightningd_network}.conf"} start_precmd="lightningd_start_precmd" pidfile="${lightningd_base_dir}/lightningd-${lightningd_network}.pid" command="%%PREFIX%%/bin/lightningd" command_args="" command_args="${command_args} --lightning-dir=${lightningd_base_dir}" command_args="${command_args} --network=${lightningd_network}" command_args="${command_args} --daemon" # service(8) would execute us with LOCALBASE stripped out from PATH, # thus specify the full path to bitcoin-cli. command_args="${command_args} --bitcoin-cli=%%LOCALBASE%%/bin/bitcoin-cli" # bitcoin-cli(1) tries to create its "datadir" (by default ${HOME}/.bitcoin) # if it does not exist. Provide something that already exists to avoid the # creation of unnecessary empty directories. command_args="${command_args} --bitcoin-datadir=${lightningd_base_dir}" if [ -e "${lightningd_conf}" ] ; then command_args="${command_args} --conf=${lightningd_conf}" fi command_args="${command_args} ${lightningd_extra_args}" check_bitcoind_ready() { %%LOCALBASE%%/bin/bitcoin-cli \ -rpcconnect=${bitcoin_addr}${bitcoin_port:+":"}${bitcoin_port} \ -rpcuser=${bitcoin_user} \ -stdinrpcpass \ echo itworks < /dev/null 2>&1; then break fi fi echo "Waiting for bitcoind to start serving RPC, lightningd cannot start without it $i" sleep 1 i=$((i - 1)) done } run_rc_command "$1"