WebFaction
Community site: login faq

I have a custom app listening on port. It is a binary executable (written in golang, but it does not matter much I think). I need to be able to start and stop the app on demand (I have a git hook that needs to stop the currently running app, rebuild it, and start the new version). How is this done properly?

asked 16 Jun '14, 16:40

akonsu
64514
accept rate: 100%


It really depends on the application itself. I'll assume your binary executable is "/home/akonsu/whatever".

Some apps are written to run as daemon processes, and include their own options for starting and stopping, like "/home/akonsu/whatever start" and "/home/akonsu/whatever stop".

If not, then to start the app, you should probably just need to execute the command, eg: "/home/akonsu/whatever".

To stop the app, you simply kill its process. A simple way to do this would be: pkill -f "/home/akonsu/whatever".

permanent link

answered 16 Jun '14, 18:54

seanf
12.2k41836
accept rate: 37%

@seanf thanks. this app is in Golang, so it does not daemonize itself, so start/stop commands are not available. My question was how can I start the app in the background from my git hook script. I am not a sysadmin, I do not know the right way to do it. Would executing a command like /home/akonsu/whatever & with the ampersand at the end be sufficient? Then maybe it would make sense to get the process id of it so that I could kill it later? the pkill seems fragile, no?

(16 Jun '14, 19:01) akonsu

Since it does not daemonize itself you can put in the script whatever you put in shell to run it, as long as you are using complete paths. Git is designed to run the post/pre commit scripts as shell scripts, and they use shell's threading. You could record PID if you wished, but should only do this if you see there is an issue with the process not terminating. I would put any kind of PID monitoring script in cron, having it read the PID from a file that was written to by the git script.

(17 Jun '14, 01:36) johns
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×24
×21

question asked: 16 Jun '14, 16:40

question was seen: 4,471 times

last updated: 17 Jun '14, 01:36

WEBFACTION
REACH US
SUPPORT
AFFILIATE PROGRAM
LEGAL
© COPYRIGHT 2003-2019 SWARMA LIMITED - WEBFACTION IS A SERVICE OF SWARMA LIMITED
REGISTERED IN ENGLAND AND WALES 5729350 - VAT REGISTRATION NUMBER 877397162
5TH FLOOR, THE OLD VINYL FACTORY, HAYES, UB3 1HA, UNITED KINGDOM