Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
sameh-farouk opened this issue Jun 7, 2021 · 0 comments
Open

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

sameh-farouk opened this issue Jun 7, 2021 · 0 comments
Labels
Projects
Milestone

Comments

@sameh-farouk
Copy link
Member

sameh-farouk commented Jun 7, 2021

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.

@sameh-farouk sameh-farouk self-assigned this Jun 7, 2021
@sameh-farouk sameh-farouk added this to the later milestone Jun 7, 2021
@sameh-farouk sameh-farouk added this to Accepted in JS-SDK 11.6 via automation Jun 20, 2021
@sameh-farouk sameh-farouk moved this from Accepted to Backlog in JS-SDK 11.6 Jun 20, 2021
@sameh-farouk sameh-farouk removed their assignment Aug 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Development

No branches or pull requests

1 participant