Sunday, April 28, 2024
 Popular · Latest · Hot · Upcoming
1
rated 0 times [  1] [ 0]  / answers: 1 / hits: 489  / 2 Years ago, tue, february 1, 2022, 2:06:04

I have a web service written in Golang that I need to fire up using Upstart.



I can run the service executable (named word) on port 5555 from within it's directory manually like so:



PORT=5555 ./word


Then curl -i http://127.0.0.1:5555/api/word returns the correct response (which is some JSON).



Now, I need to run this service via Upstart. I've written this script (called word.conf):



start on runlevel [2345]
stop on runlevel [!2345]

chdir /home/word

setgid word
setuid word

export PORT=5555
exec ./word


I run it via sudo start word



status word then tells me that the service is running and I see no errors in the Upstart error logs.



When trying to hit the service again via curl -i http://127.0.0.1:5555/api/word I get a curl: (7) couldn't connect to host error.



This seems like it has to be some sort of permissions issue, but I can't pinpoint it.



I tried removing the setgid and setuid and running with no luck. I do have a user called word.



I'm on Ubuntu 12.04.3.



Any ideas?


More From » upstart

 Answers
4

If that's your complete script, then it has a two simple problems. exec should be in a script [...] end script like this:



script
exec ./word
end script


and the export variable should be declared first with a env stanza:



env PORT=5555
export PORT


So the whole script should looks like:



start on runlevel [2345]
stop on runlevel [!2345]

chdir /home/word

setgid word
setuid word

env PORT=5555
export PORT

script
exec ./word
end script


I would also instead of calling ./word would call the interpreter first. If it's a bash script:



exec /usr/bin/env bash ./word


python:



exec /usr/bin/env python word


References:




[#29115] Tuesday, February 1, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
armis

Total Points: 38
Total Questions: 106
Total Answers: 118

Location: Mali
Member since Sat, Feb 12, 2022
2 Years ago
;