Skip to content

fix for job for apache2.service failed because the control process ex… #11

fix for job for apache2.service failed because the control process ex…

fix for job for apache2.service failed because the control process ex… #11

Workflow file for this run

name: Deploy Jupyter Book to AWS EC2
on:
push:
branches:
- master
- docs
jobs:
deploy-book:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Python 3.11
uses: actions/setup-python@v4
with:
python-version: 3.11
- name: Install dependencies
run: |
pip install -r docs/requirements.txt
- name: Cache executed notebooks
uses: actions/cache@v4
with:
path: docs/_build/.jupyter_cache
key: jupyter-book-cache-${{ hashFiles('docs/requirements.txt') }}
- name: Build the book
run: |
jupyter-book build docs/
- name: Configure SSH
run: |
mkdir -p ~/.ssh
echo "${{ secrets.EC2_SSH_KEY }}" | tr -d '\r' > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
ssh-keyscan -v -H ${{ vars.EC2_HOST }} >> ~/.ssh/known_hosts || echo "ssh-keyscan failed, continuing..."
- name: Debug Secrets and SSH
run: |
echo "Checking configuration..."
echo "SSH key exists: $(test -f ~/.ssh/id_rsa && echo 'Yes' || echo 'No')"
echo "SSH key permissions: $(ls -l ~/.ssh/id_rsa)"
echo "Known hosts file content:"
cat ~/.ssh/known_hosts || echo "No known_hosts file"
- name: Deploy to AWS EC2
env:
EC2_USER: ${{ vars.EC2_USER }}
EC2_HOST: ${{ vars.EC2_HOST }}
run: |
if [ -z "$EC2_USER" ] || [ -z "$EC2_HOST" ]; then
echo "Error: EC2_USER or EC2_HOST is empty"
exit 1
fi
echo "Starting deployment to ${EC2_HOST}..."
# Install and configure Apache
echo "Installing Apache..."
if ssh -o StrictHostKeyChecking=no "${EC2_USER}@${EC2_HOST}" "sudo apt-get update && sudo apt-get install -y apache2"; then
echo "✓ Apache installation successful"
else
echo "× Apache installation failed"
exit 1
fi
# Create directory and set permissions
echo "Creating directory and setting permissions..."
if ssh -o StrictHostKeyChecking=no "${EC2_USER}@${EC2_HOST}" "sudo mkdir -p /var/www/html/jupyterbook_8040/ && sudo chown -R ${EC2_USER}:${EC2_USER} /var/www/html/jupyterbook_8040/"; then
echo "✓ Directory setup successful"
else
echo "× Directory setup failed"
exit 1
fi
# Copy files
echo "Copying files..."
if scp -r -o StrictHostKeyChecking=no docs/_build/html/* "${EC2_USER}@${EC2_HOST}:/var/www/html/jupyterbook_8040/"; then
echo "✓ File copy successful"
else
echo "× File copy failed"
exit 1
fi
# Configure Apache
echo "Configuring Apache..."
VHOST_CONF='<VirtualHost *:8040>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html/jupyterbook_8040
<Directory /var/www/html/jupyterbook_8040>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog /var/log/apache2/error.log
CustomLog /var/log/apache2/access.log combined
</VirtualHost>'
if ssh -o StrictHostKeyChecking=no "${EC2_USER}@${EC2_HOST}" "
# Update ports.conf
sudo sed -i 's/Listen 80/Listen 8040/' /etc/apache2/ports.conf
# Disable default site
sudo a2dissite 000-default.conf
# Configure jupyterbook site
echo '$VHOST_CONF' | sudo tee /etc/apache2/sites-available/jupyterbook.conf
# Enable site and restart Apache
sudo a2ensite jupyterbook.conf
sudo systemctl restart apache2
# Check Apache status
sudo systemctl status apache2
"; then
echo "✓ Apache configuration and restart successful"
else
echo "× Apache configuration failed"
exit 1
fi
echo "✓ Site should be accessible at http://${EC2_HOST}:8040"
echo "Note: Make sure port 8040 is allowed in your EC2 security group"
echo "✓ Deployment completed successfully!"
- name: Cleanup SSH key
run: rm -f ~/.ssh/id_rsa