Skip to content

Instantly share code, notes, and snippets.

@benbjohnson
Created August 4, 2014 04:02
Show Gist options
  • Save benbjohnson/75423d651f367f9d9d13 to your computer and use it in GitHub Desktop.
Save benbjohnson/75423d651f367f9d9d13 to your computer and use it in GitHub Desktop.
Simple Go Deployment on Ubuntu

Steps

  1. Setup Go cross-compile using Dave Cheney's instructions & package.

  2. Copy the myapp.conf file to /etc/init/myapp.conf. Change the name of the service to whatever you want to call it.

  3. Change the name parameter in myapp.conf to your application's name.

  4. Change the script / end script block to whatever you need to startup your app.

Usage

To start your service:

$ sudo service myapp start

To stop your service:

$ sudo service myapp stop

You can find STDOUT automatically logged to /var/log/upstart/myapp.log.

Deployment

When you deploy, you'll need to stop the service, copy over the binary, and then start the service again.

You can use goxc and create a deb file but I think that's overkill since it's a single binary.

Other Tips

I usually create a data directory under /var/lib/myapp and I store my configuration under /etc/myapp/.

description "My App"
author "Katrina Owen"
start on filesystem
stop on runlevel [!2345]
respawn
script
/usr/local/bin/myapp \
-d /var/lib/myapp \
-c /etc/myapp/config.toml
end script
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment