Skip to content

startupcmd not able to get the process id of nginx #3166

Open
@sameh-farouk

Description

@sameh-farouk

Description

there was an issue with getting the 3bot server run without sudo on macOS because of relying on some regex to find the process. this leads us in this PR and this PR to specify a check command to execute to find if the Nginx started or not yet.

but digging into the startupcmd implementation, after discussion with @abom I find that it should be able theoretically (with the original implementation) to get the PID of the started command, and then use that to decide if the process is running, without specifying regex or check cmd.

after testing a few commands, getting the PID attribute of the startupcmd instance worked as expected, except for Nginx case, and possibly other executables.

getting PID in startupcmd depends on the usages of the exec command and passing a name for the command with the -a option.

https://github.com/threefoldtech/js-ng/blob/811a4358257556481d1a150d3499339e502eaa56/jumpscale/tools/startupcmd/startupcmd.py#L294

then to find the PID, it will try to find the process with the name set during the command execution.

https://github.com/threefoldtech/js-ng/blob/811a4358257556481d1a150d3499339e502eaa56/jumpscale/tools/startupcmd/startupcmd.py#L67-L73

the code above will try to find the process using the sals.process.get_pids() which should return a list of processes ID(s) matching a given process name, in our Nginx case, startupcmd_nginx_main. but it will fail.

checking ps command output:

sameh     359217  0.0  0.0  10328  7744 pts/5    S+   15:43   0:00 nginx: master process startupcmd_nginx_main -c /home/sameh/sandbox/cfg/nginx/main/nginx.conf

the name of the process that started is nginx, not as expected startupcmd_nginx_main.

to fix that we could search for the given name in the full command line instead of matching with only the process name part. this could be done easily, by setting the full_cmd_line parameter to True in jumpscale/tools/startupcmd/startupcmd.py.

            pids = j.sals.process.get_pids(f"startupcmd_{self.instance_name}", full_cmd_line=True)

then we could get rid of both the check_cmd and the process_strings_regex properties and is_running() will still behave as expected.

Steps to reproduce

1- create nginx startupcmd instance using startupcmd tool.
2- make sure both check_cmd and process_strings_regex properties are empty.
3- strat the cmd with start() method.
4- check the startupcmd instance pid or process properties, it won't return a result.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions