Skip to content

Commit

Permalink
New hologram-boot script that's not adroll-specific
Browse files Browse the repository at this point in the history
Previous boot script used internal adroll host for checking that network
is up. Replaced it with go binary that gets the hostname for the server
from the config file and doesn't launch "hologram" me until both network
and server are up.
  • Loading branch information
frangarciam committed Feb 20, 2015
1 parent 102b03b commit eb42ed4
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 15 deletions.
8 changes: 6 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ setup: .setup-complete

package: bin/darwin/Hologram-$(GIT_TAG).pkg bin/linux/hologram-$(GIT_TAG).deb bin/linux/hologram-server-$(GIT_TAG).deb

build: bin/darwin/hologram-server bin/linux/hologram-server bin/darwin/hologram-agent bin/linux/hologram-agent bin/darwin/hologram-cli bin/linux/hologram-cli bin/darwin/hologram-authorize bin/linux/hologram-authorize
build: bin/darwin/hologram-server bin/linux/hologram-server bin/darwin/hologram-agent bin/linux/hologram-agent bin/darwin/hologram-cli bin/linux/hologram-cli bin/darwin/hologram-authorize bin/linux/hologram-authorize bin/darwin/hologram-boot

protocol/hologram.pb.go: protocol/hologram.proto
protoc --go_out=. protocol/hologram.proto
Expand Down Expand Up @@ -60,6 +60,10 @@ bin/%/hologram-cli: protocol/hologram.pb.go cli/*/*.go log/*.go log/.deps transp
@echo "Building CLI version $(GIT_TAG)$(GIT_DIRTY)"
@cd cli/bin; gox -osarch="$*/amd64" -output="../../bin/$*/hologram-cli"

bin/darwin/hologram-boot: tools/boot/main.go
@cd tools/boot/; go build
@mv tools/boot/boot bin/darwin/hologram-boot

bin/ping: tools/ping/main.go log/*.go log/.deps
@cd tools/ping; go build
@mv tools/ping/ping bin/ping
Expand All @@ -72,7 +76,7 @@ bin/darwin/Hologram-%.pkg: bin/darwin/hologram-agent bin/darwin/hologram-cli bin
@cp ./bin/darwin/hologram-cli ./pkg/darwin/root/usr/bin/hologram
@cp ./bin/darwin/hologram-authorize ./pkg/darwin/root/usr/bin/hologram-authorize
@cp ./config/agent.json ./pkg/darwin/root/etc/hologram/agent.json
@cp ./agent/support/darwin/hologram-boot.sh ./pkg/darwin/root/usr/bin/hologram-boot
@cp ./bin/darwin/hologram-boot ./pkg/darwin/root/usr/bin/hologram-boot
@cp ./agent/support/darwin/com.adroll.hologram-ip.plist ./pkg/darwin/root/Library/LaunchDaemons
@cp ./agent/support/darwin/com.adroll.hologram.plist ./pkg/darwin/root/Library/LaunchDaemons
@cp ./agent/support/darwin/com.adroll.hologram-me.plist ./pkg/darwin/root/Library/LaunchAgents
Expand Down
13 changes: 0 additions & 13 deletions agent/support/darwin/hologram-boot.sh

This file was deleted.

63 changes: 63 additions & 0 deletions tools/boot/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// Script to launch "hologram me" as soon as the network/server are ready
//
// Copyright 2014 AdRoll, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package main

import (
"encoding/json"
"io/ioutil"
"log"
"net"
"os/exec"
"time"
)

const configFile = "/etc/hologram/agent.json"

type Config struct {
Host string `json:"host"`
}

func main() {
var config Config
contents, err := ioutil.ReadFile(configFile)
if err != nil {
log.Fatal(err)
}

err = json.Unmarshal(contents, &config)
if err != nil {
log.Fatal(err)
}

for {
time.Sleep(1 * time.Second)
_, err := net.Dial("tcp", config.Host)
if err != nil {
// TODO: Better error handling. Exponential backoff if server is truly down
log.Println("Error connecting to server", err)
continue
}

log.Println("Booting hologram...")
cmd := exec.Command("/usr/bin/hologram", "me")
err = cmd.Run()
if err != nil {
log.Fatal("Error when starting up hologram", err)
}
break
}
}

0 comments on commit eb42ed4

Please sign in to comment.