#Usage
Install watchman, and then run ./autobuild.
Modify restart such that it builds your project appropriately, and modify the ENV=some_program line to instead be whatever program you wanted to run.
| #!/bin/sh | |
| watchman-make --make './restart' -p '**/*.go' -t ignored |
| package main | |
| import ( | |
| "fmt" | |
| ) | |
| func main() { | |
| fmt.Println("HELLO WORLD!") | |
| } |
| #!/bin/sh | |
| EXE=./some_program | |
| PIDFILE=pid/service.pid | |
| msg() { | |
| echo -e "\e[92m$@\e[0m" | |
| } | |
| # kill existing process | |
| if [ -f $PIDFILE ]; then | |
| pid=$(cat $PIDFILE) | |
| msg "killing previous process ($pid) . . ." | |
| kill $pid >/dev/null 2>&1 | |
| # wait for it to die | |
| while kill -0 $pid >/dev/null 2>&1; do | |
| msg "waiting for process to exit . . ." | |
| sleep 0.5 | |
| done | |
| fi | |
| msg "building project . . ." | |
| go build -o some_program main.go | |
| msg "starting new process . . ." | |
| # fork, so watchman-make doesn't hang. | |
| exec $EXE & | |
| # write the new PIDFILE | |
| mkdir -p $(dirname $PIDFILE) | |
| echo $! > $PIDFILE |