diff --git a/conf/systemd.service b/conf/systemd.service index c9aed58..2c69049 100644 --- a/conf/systemd.service +++ b/conf/systemd.service @@ -7,7 +7,7 @@ User=__APP__ Group=__APP__ WorkingDirectory=__DATA_DIR__/ -ExecStart=__DATA_DIR__/venv/bin/gunicorn --config __DATA_DIR__/gunicorn.conf.py FastAPIAppFolder:app --worker-class uvicorn.workers.UvicornWorker +ExecStart=__INSTALL_DIR__/venv/bin/gunicorn --config __INSTALL_DIR__/gunicorn.conf.py FastAPIAppFolder:app --worker-class uvicorn.workers.UvicornWorker StandardOutput=syslog StandardError=syslog diff --git a/manifest.toml b/manifest.toml index 8e1f9ff..3ddc348 100644 --- a/manifest.toml +++ b/manifest.toml @@ -41,6 +41,8 @@ ram.runtime = "50M" [resources.system_user] # This will provision/deprovision a unix system user + [resources.install_dir] + [resources.data_dir] # This will create/remove the data dir as /home/yunohost.app/$app # and store the corresponding setting $data_dir diff --git a/scripts/_common.sh b/scripts/_common.sh index 9ce0c03..f7cb326 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -22,8 +22,8 @@ log_level="WARNING" # SET CONSTANTS #================================================= -# e.g.: point pip cache to: /home/yunohost.app/$app/.cache/ -XDG_CACHE_HOME="$data_dir/.cache/" +# e.g.: point pip cache to: /var/www/$app/.cache/ +XDG_CACHE_HOME="$install_dir/.cache/" log_path=/var/log/$app log_file="${log_path}/${app}.log" @@ -34,22 +34,23 @@ log_file="${log_path}/${app}.log" myynh_setup_python_venv() { # Always recreate everything fresh with current python version - ynh_secure_remove "$data_dir/venv" + ynh_secure_remove "$install_dir/venv" # Skip pip because of: https://github.com/YunoHost/issues/issues/1960 - python3 -m venv --without-pip "$data_dir/venv" + python3 -m venv --without-pip "$install_dir/venv" - chown -c -R "$app:" "$data_dir" + chown -c -R "$app:" "$install_dir" # run source in a 'sub shell' ( set +o nounset - source "$data_dir/venv/bin/activate" + source "$install_dir/venv/bin/activate" set -o nounset set -x - ynh_exec_as $app $data_dir/venv/bin/python3 -m ensurepip - ynh_exec_as $app $data_dir/venv/bin/pip3 install --upgrade wheel pip setuptools - ynh_exec_as $app $data_dir/venv/bin/pip3 install -r "$data_dir/requirements.txt" + ynh_exec_as $app $install_dir/venv/bin/python3 -m ensurepip + # using --no-cache-dir option because user doesn't have permission to write on cache directory (don't know if it's on purpose or not) + ynh_exec_as $app $install_dir/venv/bin/pip3 install --no-cache-dir --upgrade wheel pip setuptools + ynh_exec_as $app $install_dir/venv/bin/pip3 install --no-cache-dir -r "$install_dir/requirements.txt" ) } @@ -72,5 +73,9 @@ myynh_fix_file_permissions() { # /home/yunohost.app/$app/ chown -c -R "$app:" "$data_dir" chmod -c o-rwx "$data_dir" + + # /var/www/$app/ + chown -c -R "$app:" "$install_dir" + chmod -c o-rwx "$install_dir" ) } \ No newline at end of file diff --git a/scripts/install b/scripts/install index 804b330..d428c24 100755 --- a/scripts/install +++ b/scripts/install @@ -55,7 +55,7 @@ ynh_use_logrotate --logfile="$log_file" --specific_user=$app #================================================= ynh_script_progression --message="Create and setup Python virtualenv..." --weight=45 -ynh_add_config --template="requirements.txt" --destination="$data_dir/requirements.txt" +ynh_add_config --template="requirements.txt" --destination="$install_dir/requirements.txt" myynh_setup_python_venv @@ -64,7 +64,7 @@ myynh_setup_python_venv # ================================================ ynh_script_progression --message="Create $app configuration files..." -ynh_add_config --template="gunicorn.conf.py" --destination="$data_dir/gunicorn.conf.py" +ynh_add_config --template="gunicorn.conf.py" --destination="$install_dir/gunicorn.conf.py" mkdir -p "$data_dir/FastAPIAppFolder" ynh_add_config --template="__init__.py" --destination="$data_dir/FastAPIAppFolder/__init__.py"