From 4202d99978a106a629c69958be92e365d5f12348 Mon Sep 17 00:00:00 2001 From: John Lauer Date: Sat, 25 Nov 2017 11:48:53 -0800 Subject: [PATCH] Finished /etc/init.d script create --- initd_script.go | 20 +++++++++++++++++++- main.go | 2 +- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/initd_script.go b/initd_script.go index d6ad108..b7796fd 100644 --- a/initd_script.go +++ b/initd_script.go @@ -4,6 +4,7 @@ import ( "io/ioutil" "log" "os" + "os/exec" ) func check(e error) { @@ -41,7 +42,7 @@ case "$1" in start) log_begin_msg "Starting Serial Port JSON Server service" # do something - ` + exeName + ` -regex usb|acm & + ` + exeName + ` & log_end_msg $? exit 0 ;; @@ -64,4 +65,21 @@ esac d1 := []byte(script) err2 := ioutil.WriteFile("/etc/init.d/serial-port-json-server", d1, 0755) check(err2) + + // install it + // sudo update-rc.d serial-port-json-server defaults + cmd := exec.Command("update-rc.d", "serial-port-json-server", "defaults") + err3 := cmd.Start() + if err3 != nil { + log.Fatal(err3) + } + log.Printf("Waiting for command to finish...") + err4 := cmd.Wait() + if err4 != nil { + log.Printf("Command finished with error: %v", err4) + } else { + log.Printf("Successfully created your startup script in /etc/init.d") + log.Printf("You can now run /etc/init.id/serial-port-json-server start and this will run automatically on startup") + } + } diff --git a/main.go b/main.go index 53e37c1..6bb8eb7 100755 --- a/main.go +++ b/main.go @@ -164,7 +164,7 @@ func main() { // serial port list thread go func() { - time.Sleep(300 * time.Millisecond) + time.Sleep(1300 * time.Millisecond) log.SetOutput(io.Writer(os.Stdout)) log.Println("Your serial ports:") if len(portList) == 0 {