Sample Header Ad - 728x90

Asynchronous Child Process in FastCGI Script

2 votes
2 answers
497 views
Suppose that I want my server to sleep on any HTTP request to the path /sleep (i.e. http://hostname/sleep ), but also send a complete response (HTTP 200) before sleeping. Using **nginx** with **FastCGI** , I have configured the path in the **nginx** configuration: location /sleep { fastcgi_pass unix:/path/to/fcgiwrap.socket; include fastcgi_params; fastcgi_param SCRIPT_FILENAME /path/to/script.sh; } This invokes the following script (/path/to/script.sh): #!/bin/sh # -*- coding: utf-8 -*- cat Sleep

Sleep: $(date)

EOF sleep 1 && sudo systemctl suspend /dev/null 2>&1 & Even though this will sleep the system, **FastCGI** will block until the child process completes, meaning that the web request will not complete before the system sleeps. So, how do I detach that final command from oversight by **FastCGI** so that the response completes, yet the command continues in the background, in this case ultimately to sleep the system?
Asked by palswim (5597 rep)
Jun 5, 2021, 05:50 AM
Last activity: Jun 10, 2021, 08:47 PM