Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Stopping service does not work when using script options #96

@thosaa

Description

@thosaa

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions