Python rc scripts and $HOME

I use an rc script to start an application server (gunicorn), which needs to consult configuration files for PostgreSQL. These files are placed in the home directory of the user running gunicorn, but PostgreSQL does not find them there. When placing the files in a system-wide config directory (/usr/local/etc/postgresql) and referencing its full path (/home/www/.pgpass), everything works, but I wonder why /home/www is not checked automatically (as per the PostgreSQL documentation). On my local development machine (macOS), the files are found in the gunicorn user's home directory without absolute paths. Is the $HOME variable not set to the user running a process in the rc script?
 
Did you install www/py-gunicorn? It comes with an rc(8) script.
No, I installed gunicorn via pip and created a rc(8) script manually:
Code:
. /etc/rc.subr

name="gunicorn"
rcvar=gunicorn_enable

load_rc_config $name

: ${gunicorn_enable:="NO"}
: ${gunicorn_app:="myapp.wsgi:application"}
: ${gunicorn_chdir:="/var/www/myapp"}
: ${gunicorn_user:="www"}
: ${gunicorn_bind_ipv4:="10.95.0.20:8000"}
: ${gunicorn_bind_ipv6:="[fdb6:1b5:3992:e964::20]:8000"}
: ${gunicorn_workers:="4"}
: ${gunicorn_pidfile:="/var/run/${name}.pid"}
: ${gunicorn_logfile:="/var/log/${name}.log"}
: ${gunicorn_python:="/usr/local/virtualdjango/bin/python3.12"}
: ${gunicorn_gunicorn:="/usr/local/virtualdjango/bin/gunicorn"}
: ${gunicorn_flags:=""}

pidfile="${gunicorn_pidfile}"
command="${gunicorn_gunicorn}"
command_interpreter="${gunicorn_python}"
command_args="--bind ${gunicorn_bind_ipv4} --bind ${gunicorn_bind_ipv6} \
    --workers ${gunicorn_workers} \
    --pid ${gunicorn_pidfile} \
    --chdir ${gunicorn_chdir} \
    --daemon \
    ${gunicorn_flags} \
    ${gunicorn_app}"

start_precmd="${name}_prestart"

gunicorn_prestart()
{
    install -d -o ${gunicorn_user} -g ${gunicorn_user} -m 755 $(dirname ${gunicorn_pidfile})
    install -d -o ${gunicorn_user} -g ${gunicorn_user} -m 755 $(dirname ${gunicorn_logfile})
}

run_rc_command "$1"

Because the script is executed as root, I also tried placing the files in /root, but since they are opened by the gunicorn process (not the rc script), that did not work.
 
Just install the port/package. Its rc(8) script works.

Code:
#  gunicorn_enable (bool):  Set to "NO" by default.
#			    Set it to "YES" to enable gunicorn.
#
# gunicorn_config (str):    Path to gunicorn config file.
#
# gunicorn_user (str):      User to run gunicorn as.
#
# gunicorn_group (str):     Group to run gunicorn as.
#
# gunicorn_profiles (str):  Set to "" by default.
#                           Define your profiles here.

Now, I see you appear to want to use Python 3.12. That should be fine, but the package will use 3.11 (that's the 'default' Python version at this time).

Set in /etc/make.conf:
Code:
DEFAULT_VERSIONS+= python=3.12
And build www/py-gunicorn from ports. Then it should use Python 3.12.
 
Just install the port/package. Its rc(8) script works.
Works with the PostgreSQL configuration files in /home/<user>? I will just inspect the rc script from the package. then. Thank you!

Now, I see you appear to want to use Python 3.12. That should be fine, but the package will use 3.11 (that's the 'default' Python version at this time).
Yes, current Django versions require Python >= 3.12.
 
Back
Top