Skip to content
This repository was archived by the owner on Mar 27, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Install Service at first run
Needs sudo/root capabilities
  • Loading branch information
facchinm committed Jun 13, 2017
commit 6539a7ad77fb380bfeb817f24338e57d62a01e1f
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const (
configFile = "./arduino-connector.cfg"
)

func main() {
func (p *Program) run() {
var (
id = flag.String("id", "", "id of the thing in aws iot")
uuid = flag.String("uuid", "", "A uuid generated the first time the connector is started")
Expand Down
54 changes: 54 additions & 0 deletions service.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// simple does nothing except block while running the service.
package main

import (
"log"

"github.com/kardianos/osext"
"github.com/kardianos/service"
)

var logger service.Logger

type Program struct{}

func (p *Program) Start(s service.Service) error {
// Start should not block. Do the actual work async.
go p.run()
return nil
}

func (p *Program) Stop(s service.Service) error {
// Stop should not block. Return with a few seconds.
return nil
}

func main() {

workingDirectory, _ := osext.ExecutableFolder()

svcConfig := &service.Config{
Name: "ArduinoConnector",
DisplayName: "Arduino Connector Service",
Description: "Cloud connector and launcher for Intel IoT devices.",
WorkingDirectory: workingDirectory,
}

prg := &Program{}
s, err := service.New(prg, svcConfig)
if err != nil {
log.Fatal(err)
}
logger, err = s.Logger(nil)
if err != nil {
log.Fatal(err)
}
if service.Interactive() {
log.Println("Installing service")
s.Install()
}
err = s.Run()
if err != nil {
logger.Error(err)
}
}