zapty / forever-service

Provision node script as a service via forever, allowing it to automatically start on boot, working across various Linux distros and OS
https://github.com/zapty/forever-service
MIT License
594 stars 65 forks source link

Stopping service does not work when using script options #96

Open thosaa opened 6 years ago

thosaa commented 6 years ago

https://github.com/zapty/forever-service/blob/54a2ad4ea2f344c27c92ce7944e3a014d092019a/templates/sysvinit/initd.template#L161 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