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

Stopping service does not work when using script options #96

Open
thosaa opened this issue Oct 17, 2017 · 0 comments
Open

Stopping service does not work when using script options #96

thosaa opened this issue Oct 17, 2017 · 0 comments

Comments

@thosaa
Copy link

thosaa commented Oct 17, 2017

PID=$({{foreverPath}}forever --plain list | sed -n -e '/data:\s*\[[0-9]*\]\s\({{service}}\)\s/p' | awk '{print $7}')

I have created the service with the install command:
sudo forever-service install randomService --script /opt/randomService/bin/www --scriptOptions " --option1=\"One\" --option2=2 --option3=3" --start

The service is created, enabled and is running.

I then went ahead and tried to stop the service using:
sudo service randomService stop
Which returns successfully.

Testing with sudo forever list however, shows that the process was not stopped.
Investigating this i found that the service script '/etc/init.d/randomService' are using the 'forever list' piped through sed and awk to find the PID. But awk is always looking at index seven: awk '{print $7}'

Running this command-set in cli returned '--option2=2' instead of the PID...

Instead of counting from the beginning and handle the variable command width it could be fixed by counting from the end instead using awk '{print $(NF-2)}'.

I do not think that this would break anything, but please prove me wrong.

Example

Cmd:
sudo /usr/bin/forever --plain list | sed -n -e '/data:\s*\[[0-9]*\]\s\(randomService\)\s/p'
Result:
data: [0] randomService /usr/bin/node /opt/randomService/bin/www --option1=\"One\" --option2=2 --option3=3 543 555 /var/log/randomService.log 0:2:27:7.595

Piping through awk as in the current template:
sudo /usr/bin/forever --plain list | sed -n -e '/data:\s*\[[0-9]*\]\s\(randomService\)\s/p' | awk '{print $7}'
Result:
--option2=2

Piping through awk counting from the back:
sudo /usr/bin/forever --plain list | sed -n -e '/data:\s*\[[0-9]*\]\s\(randomService\)\s/p' | awk '{print $(NF-2)}
Result:
555

Regards
Thomas

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant