diff --git a/update-nginx-config.sh b/update-nginx-config.sh index 8781d4f..78a25c7 100755 --- a/update-nginx-config.sh +++ b/update-nginx-config.sh @@ -93,14 +93,19 @@ EOL echo "Uploading new configuration..." scp boilerhaus.org.conf.new $SERVER_USER@$SERVER_IP:/etc/nginx/sites-available/boilerhaus.org.conf +# Make sure the site is enabled +echo "Ensuring site is enabled..." +ssh $SERVER_USER@$SERVER_IP "ln -sf /etc/nginx/sites-available/boilerhaus.org.conf /etc/nginx/sites-enabled/boilerhaus.org.conf" + # Test Nginx configuration echo "Testing Nginx configuration..." ssh $SERVER_USER@$SERVER_IP "nginx -t" -# If the test is successful, reload Nginx +# If the test is successful, start or reload Nginx if [ $? -eq 0 ]; then - echo "Reloading Nginx..." - ssh $SERVER_USER@$SERVER_IP "systemctl reload nginx" + echo "Starting or reloading Nginx..." + ssh $SERVER_USER@$SERVER_IP "systemctl is-active nginx || systemctl start nginx" + ssh $SERVER_USER@$SERVER_IP "systemctl reload nginx || systemctl restart nginx" echo "Configuration updated successfully!" else echo "Nginx configuration test failed. Restoring backup..." @@ -108,12 +113,8 @@ else echo "Backup restored. Please check the configuration and try again." fi -# Make sure the site is enabled -echo "Ensuring site is enabled..." -ssh $SERVER_USER@$SERVER_IP "ln -sf /etc/nginx/sites-available/boilerhaus.org.conf /etc/nginx/sites-enabled/boilerhaus.org.conf" - # Run Certbot to ensure SSL certificates are set up for all domains echo "Running Certbot to ensure SSL certificates are set up..." -ssh $SERVER_USER@$SERVER_IP "certbot --nginx -d boilerhaus.org -d www.boilerhaus.org -d cloud.boilerhaus.org -d git.boilerhaus.org -d bw.boilerhaus.org --non-interactive --agree-tos --email admin@boilerhaus.org" +ssh $SERVER_USER@$SERVER_IP "certbot --nginx --expand -d boilerhaus.org -d www.boilerhaus.org -d cloud.boilerhaus.org -d git.boilerhaus.org -d bw.boilerhaus.org --non-interactive --agree-tos --email admin@boilerhaus.org" echo "Done!" \ No newline at end of file