From 605e458130cbbc130f025007f8b2a161ecfee7ab Mon Sep 17 00:00:00 2001 From: Ikechukwu Date: Tue, 15 Apr 2025 18:41:15 +0800 Subject: [PATCH 1/2] debian 12 changes --- cookbooks/supervisor/recipes/default.rb | 30 +++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/cookbooks/supervisor/recipes/default.rb b/cookbooks/supervisor/recipes/default.rb index db4c24cf..35ff57da 100644 --- a/cookbooks/supervisor/recipes/default.rb +++ b/cookbooks/supervisor/recipes/default.rb @@ -25,8 +25,34 @@ end end -execute 'pip install supervisor' do - command 'pip install supervisor --index=https://pypi.python.org/simple/' +# In Debian 12+, pip cannot install packages system-wide due to PEP 668 +# We need to create a virtual environment for supervisor +if platform?('debian') && node['platform_version'].to_i >= 12 + # Ensure python3-venv is installed + package 'python3-venv' + + # Create a virtual environment for supervisor + execute 'create supervisor venv' do + command 'python3 -m venv /opt/supervisor-venv' + not_if { ::Dir.exist?('/opt/supervisor-venv') } + end + + # Install supervisor in the virtual environment + execute 'install supervisor in venv' do + command '/opt/supervisor-venv/bin/pip install supervisor --index=https://pypi.python.org/simple/' + end + + # Create symlinks to make supervisor commands accessible system-wide + %w(supervisord supervisorctl).each do |cmd| + link "/usr/local/bin/#{cmd}" do + to "/opt/supervisor-venv/bin/#{cmd}" + end + end +else + # For older Debian versions or other platforms, install directly with pip + execute 'pip install supervisor' do + command 'pip install supervisor --index=https://pypi.python.org/simple/' + end end directory node['supervisor']['dir'] do From d9bdf8872f751904f1561c05e9b0a4e47f4476ae Mon Sep 17 00:00:00 2001 From: Ikechukwu Date: Wed, 16 Apr 2025 12:19:33 +0800 Subject: [PATCH 2/2] wip --- cookbooks/supervisor/recipes/default.rb | 36 ++++++++++--------------- 1 file changed, 14 insertions(+), 22 deletions(-) diff --git a/cookbooks/supervisor/recipes/default.rb b/cookbooks/supervisor/recipes/default.rb index 35ff57da..899e5ad2 100644 --- a/cookbooks/supervisor/recipes/default.rb +++ b/cookbooks/supervisor/recipes/default.rb @@ -17,7 +17,6 @@ # limitations under the License. # - # foodcritic FC023: we prefer not having the resource on non-smartos if platform_family?('smartos') package 'py27-expat' do @@ -26,27 +25,20 @@ end # In Debian 12+, pip cannot install packages system-wide due to PEP 668 -# We need to create a virtual environment for supervisor if platform?('debian') && node['platform_version'].to_i >= 12 - # Ensure python3-venv is installed - package 'python3-venv' - - # Create a virtual environment for supervisor - execute 'create supervisor venv' do - command 'python3 -m venv /opt/supervisor-venv' - not_if { ::Dir.exist?('/opt/supervisor-venv') } - end - - # Install supervisor in the virtual environment - execute 'install supervisor in venv' do - command '/opt/supervisor-venv/bin/pip install supervisor --index=https://pypi.python.org/simple/' + # Install pipx for isolated Python package installation + package 'pipx' + + # Ensure pipx is in PATH + execute 'pipx ensurepath' do + command 'pipx ensurepath' + not_if 'grep -q "PATH.*\.local/bin" /etc/environment' end - - # Create symlinks to make supervisor commands accessible system-wide - %w(supervisord supervisorctl).each do |cmd| - link "/usr/local/bin/#{cmd}" do - to "/opt/supervisor-venv/bin/#{cmd}" - end + + # Install supervisor using pipx + execute 'install supervisor with pipx' do + command 'pipx install supervisor --index=https://pypi.python.org/simple/' + not_if 'pipx list | grep -q supervisor' end else # For older Debian versions or other platforms, install directly with pip @@ -75,8 +67,8 @@ supervisord_minfds: node['supervisor']['minfds'], supervisord_minprocs: node['supervisor']['minprocs'], supervisor_version: node['supervisor']['version'], - socket_file: node['supervisor']['socket_file'] - } + socket_file: node['supervisor']['socket_file'], + } end) end