Posts Tagged service

Creating ubuntu service for go app

Step 1

Install go program with go install in the app folder

Step 2

Download service script file from here: Service for go app

Step 3

Change {{USERNAME}} in the script to the user you use in ubuntu to run your app and change  {{APPNAME}}  to binary name in your $GOPATH/bin/, if needed fix the path in cmd variable to point to your own $GOPATH folder

Step 4

Rename the service remove ending ‘.sh’ and copy the service file in the folder  /etc/init.d/

Step 5

Run in the terminal chmod 700 /etc/init.d/goappservice

Step 6

Run sudo update-rc.d goappservice defaults

Step 7

Run sudo update-rc.d goappservice enable

Done!

Use usual service commands to work with your new service.

sudo service goappservice start|stop|restart|status

If there is a new version of the app then just run go install in the app folder and restart the service.

Enjoy

, ,

Leave a comment

Configure Ubuntu to work as GO web server

Картинки по запросуI’m often creating go apps or services using Digital Ocean droplets with Ubuntu, that’s why I decided to create a script to automate configuration process.

 

The script is doing following:

  1. Installs and configures firewall (ufw, allows only ports 80, 443 & 22)
  2. Installs git (required by go)
  3. Installs mysql and secures it with mysql_install_db
  4. Installs the latest version of GO (1.7.5), configures go environment (PATH, GOPATH)
  5. Installs go application from public git repository, yours or my demo (development for private is in progress) with ‘go get’
  6. Configures go app to work as a service (add config into /etc/init.d), starts the service
  7. Installs and configures nginx to work as proxy for go app

Script can be started directly from github:

bash <(curl -s https://raw.githubusercontent.com/bykovme/webgolangdo/master/preparegolangapp.sh)

Check the script and find more information here: https://github.com/bykovme/webgolangdo

, , , , , , , , , , , , , ,

Leave a comment