FreeBSD noob here, coming from some experience with Linux and systemd.
I'm running ElectrumX which is a python3.6 script and want to have an rc.d script to control it. Electrumx reads it configuration variables from environment variables. In systemd config files I had a line like ENVIRONMENTFILE=/path/to/electrumx.confg
for systemd to load all the variables into memory. The config file looks like this:
Code:
COIN=BitcoinSegwitNET=mainnetCACHE_MB=384BANNER_FILE=/var/db/electrumx/banner.txtEtc.Etc.
For an rc.d scripted system the author recommends using his shell script
run_electrumx that basically just adds an export
in front of every variable, then it runs the
python script.
run_electrumxlooks like this:
Code:
#!/usr/local/bin/bash################ run_electrumx###############export COIN=BitcoinSegwitexport NET=mainnetexport CACHE_MB=384export BANNER_FILE=/var/db/electrumx/banner.txt# connectivityexport HOST=export RPC_PORT=0export TCP_PORT=50001export SSL_PORT=50002export SSL_CERTFILE=/var/db/electrumx/server.crtexport SSL_KEYFILE=/var/db/electrumx/server.keyexport PEER_DISCOVERY=selfexport DB_DIRECTORY=/var/db/electrumx/db/usr/local/bin/electrumx_server 2>> /var/log/electrumx >> /var/log/electrumx &
My problem is that
electrumx_serverdoesn't generate a PID file so rc.subr(8) has no way of knowing if it's running. The problem with this startup script is that it launches
electrumx_serverthen quits so rc.subr(8) can't tell if electrumx is running either and is no more useful than just a boring init script.
I tried creating my own startup script startex.sh that loads the environment variables, sends logging to syslog, and creates a PID file with the pid of electrumx_server:
Code:
#!/usr/local/bin/bash#sends outputs to syslogexec 1> >(logger -p daemon.notice -t electrumx) 2>&1#Tells BASH to export all variablesset -o allexport#Tells BASH to load the config file into environment variablessource $electrumx_configset +o allexport#the & disown run the server script then detach it. Othwerwise terminal just sits there until it terminates./usr/local/bin/electrumx_server & disown#copies the PID to a variable and prints it to the electrumx PID filePID=$!echo $PID > $electrumx_pid
and edited my rc.d script to include the pid file:
Code:
#!/bin/sh# PROVIDE: electrumx# REQUIRE: bitcoin# KEYWORD: shutdown## Add the following lines to /etc/rc.conf.local or /etc/rc.conf# to enable this service:## electrumx_enable (bool): Set to NO by default.# Set it to YES to enable bitcoin.# electrumx_config (path): Set to /var/local/electrumx/electrumx.conf# by default.. /etc/rc.subrname=electrumxrcvar=electrumx_enable: ${electrumx_enable:=NO}: ${electrumx_config=/var/local/electrumx/electrumx.conf}: ${electrumx_user="electrumx"}: ${electrumx_group="electrumx"}required_files=${electrumx_config}pidfile="/var/local/electrumx/electrumx.pid"start_precmd=electrumx_prestartcommand_interpreter="/usr/local/bin/bash" command="/usr/local/sbin/startex.sh"electrumx_prestart(){ export electrumx_config=$electrumx_config export electrumx_pid=$pidfile}load_rc_config $namerun_rc_command "$1"
When I run service start electrumx
it starts successfully. cat /var/local/electrumx/electrumx.pid
returns the correct PID, but service
doesn't seems to recognize the PID file:
Code:
% sudo service electrumx statuselectrumx is not running.%
I'm flat out of ideas here. Why doesn't service see the pid file?