RE: deploying Go to ubuntu, upstart script?

3,282 views
Skip to first unread message

S Ahmed

unread,
Jun 13, 2013, 9:50:20 AM6/13/13
to golan...@googlegroups.com
Are they are tutorials on deploying a go application to ubuntu, and is it common to use upstart to start the process?


James Bardin

unread,
Jun 13, 2013, 10:12:37 AM6/13/13
to golan...@googlegroups.com


On Thursday, June 13, 2013 9:50:20 AM UTC-4, gitted wrote:
Are they are tutorials on deploying a go application to ubuntu, and is it common to use upstart to start the process?



There's nothing  special about deploying a go application vs any other binary. Upstart is great for this task, since there's no easy way for a go executable to daemonize itself, and upstart can run and manage the process itself.

Dave Cheney

unread,
Jun 13, 2013, 10:16:09 AM6/13/13
to S Ahmed, golan...@googlegroups.com
Yes, we do that in Juju. 



On 13/06/2013, at 23:50, S Ahmed <sahme...@gmail.com> wrote:

Are they are tutorials on deploying a go application to ubuntu, and is it common to use upstart to start the process?


--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

S Ahmed

unread,
Jun 13, 2013, 11:24:30 AM6/13/13
to golan...@googlegroups.com
Where can I see a sample upstart script, preferentially something someone uses in production?


--

Daniel Theophanes

unread,
Jun 13, 2013, 11:33:37 AM6/13/13
to golan...@googlegroups.com
The service package: bitbucket.org/kardianos/service
contains an example of a upstart script. Though if you use the package itself, you can just let the package handle it.

-Daniel

S Ahmed

unread,
Jun 13, 2013, 11:44:12 AM6/13/13
to golan...@googlegroups.com
Interesting package...but I don't see any upstart script in there?

James Bardin

unread,
Jun 13, 2013, 11:46:50 AM6/13/13
to golan...@googlegroups.com
What you need really depends on your program. There's not too much needed in an upstart config.
Maybe take a look at some of the conf files on your system, or from a similar service, and checkout http://upstart.ubuntu.com/cookbook/ too.

zareo...@gmail.com

unread,
Jun 13, 2013, 11:52:35 AM6/13/13
to golan...@googlegroups.com

Hi Gitted!
The script in inside the Go code itself, as a template. 

var upstartScript = `# {{.Description}}

description     "{{.Display}}"

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

#setuid username

kill signal INT

respawn
respawn limit 10 5
umask 022

console none

pre-start script
    test -x {{.Path}} || { stop; exit 0; }
end script

# Start
exec {{.Path}}
`

Daniel Theophanes

unread,
Jun 13, 2013, 11:54:07 AM6/13/13
to James Bardin, golang-nuts
https://bitbucket.org/kardianos/service/src/6e2543d89d91bc48dde7692805c1bce04f4b09f6/service_linux.go?at=default#cl-112
> You received this message because you are subscribed to a topic in the
> Google Groups "golang-nuts" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/golang-nuts/uBrN-G7anKg/unsubscribe?hl=en-US.
> To unsubscribe from this group and all its topics, send an email to

Shivakumar GN

unread,
Jun 13, 2013, 12:14:37 PM6/13/13
to S Ahmed, golan...@googlegroups.com
Just like any upstart configuration. Ex:


author "xyz"
description "xyz"
version "xyz v0.1"

start on started network
stop on stopping network

console output
respawn

# Allow go process to use 2 CPUs
env GOMAXPROCS=2

# if start directory is important
chdir /var/tmp
/var/tmp/xyz_binary



adnaan badr

unread,
Jun 13, 2013, 3:19:55 PM6/13/13
to golan...@googlegroups.com
Hey I wrote about it a while ago:

Matt Silverlock

unread,
Jun 13, 2013, 6:35:34 PM6/13/13
to golan...@googlegroups.com
Upstart can definitely do the job. It's pretty simple & works well.

You can also take a look at supervisord (http://supervisord.org/), which is a little more flexible and can restart your binary when/if it crashes, on top of other things.

Gustavo Niemeyer

unread,
Jun 13, 2013, 7:07:11 PM6/13/13
to Matt Silverlock, golan...@googlegroups.com

Upstart restarts on crashes as well.

Dave Cheney

unread,
Jun 13, 2013, 8:36:14 PM6/13/13
to Gustavo Niemeyer, Matt Silverlock, golang-nuts
Here is a sample upstart configuration that manages a juju agent process.

$ cat /etc/init/jujud-machine-0.conf
description "juju machine-0 agent"
author "Juju Team <ju...@lists.ubuntu.com>"
start on runlevel [2345]
stop on runlevel [!2345]
respawn
normal exit 0

limit nofile 20000 20000

exec /var/lib/juju/tools/machine-0/jujud machine --log-file
/var/log/juju/machine-0.log --data-dir '/var/lib/juju' --machine-id 0
--debug >> /var/log/juju/machine-0.log 2>&1
Message has been deleted

Joshua Poehls

unread,
Jun 13, 2013, 10:29:50 PM6/13/13
to golan...@googlegroups.com
Just wanted to say thanks for asking this, and thanks everyone for the great answers! I'm not at all familiar with running services on linux and have been meaning to figure out an Upstart script for my Go web app. This thread was a very pleasant gift tonight.

Do you tend to manually install the upstart script manually when setting up your app on a server or do you use a bash (or other) script for bootstrapping the server for your app, including creating the upstart script? I'm leaning towards creating a bootstrap type script that would do this and any examples of what you all use would be great.

Matt Silverlock

unread,
Jun 14, 2013, 10:49:31 AM6/14/13
to golan...@googlegroups.com


On Friday, June 14, 2013 10:29:50 AM UTC+8, Joshua Poehls wrote:

Do you tend to manually install the upstart script manually when setting up your app on a server or do you use a bash (or other) script for bootstrapping the server for your app, including creating the upstart script? I'm leaning towards creating a bootstrap type script that would do this and any examples of what you all use would be great.

Totally up to you. A bash script is fine, but tools like Puppet (https://puppetlabs.com/) and Chef Solo (http://docs.opscode.com/chef_solo.html) are pretty powerful and (IMO) easy to pick up, at least for basic tasks. If you're planning to automate deployment then they become invaluable once you get beyond one machine. 
Reply all
Reply to author
Forward
0 new messages