Skip to content

Commit

Permalink
Finished /etc/init.d script create
Browse files Browse the repository at this point in the history
  • Loading branch information
chilipeppr committed Nov 25, 2017
1 parent 19023d5 commit 4202d99
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
20 changes: 19 additions & 1 deletion initd_script.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"io/ioutil"
"log"
"os"
"os/exec"
)

func check(e error) {
Expand Down Expand Up @@ -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
;;
Expand All @@ -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")
}

}
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 4202d99

Please sign in to comment.