Instead of running the nginx
from service. Run service nginx stop
and then run
strace nginx -g "daemon off;"
this will make sure that you get the trace of the process. The -g "daemon off;"
will make sure the nginx is not run as a daemon process, else again the strace would end
Service command is just activating a process and if you want to strace
it the best is to launch the process directly.
In case you are still interested in debugging the process started using the service command. Then do below
service nginx start
ps aux | grep nginx
Capture the pid
from the nginx process and then attach to it using
strace -p <pid>
Forking Processes
To trace processes which fork, you need to use the -f
flag
strace -f nginx
Service tracing
When you call service start nginx
, assuming the system uses systemd
, the call gets translated to systemctl start nginx
. Now if you look at the source code of systemd
https://github.com/systemd/systemd/blob/cf45dd36282368d5cdf757cac2cf1fc2b562dab2/src/systemctl/systemctl.c#L3100
r = sd_bus_call_method_async(
bus,
NULL,
"org.freedesktop.systemd1",
"/org/freedesktop/systemd1",
"org.freedesktop.systemd1.Manager",
"Subscribe",
NULL, NULL,
NULL);
It doesn't spawn/fork the process. It sends the message to the systemd service which then starts nginx
process.
So in short, NO you can't strace through your service nginx start
command.