Skip to content

Instantly share code, notes, and snippets.

@sergey-cheperis
Created November 13, 2021 13:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sergey-cheperis/05097247701ef9cbfebe8cfd38aea838 to your computer and use it in GitHub Desktop.
Save sergey-cheperis/05097247701ef9cbfebe8cfd38aea838 to your computer and use it in GitHub Desktop.
Generic Makefile for a Go daemon
PREFIX=/usr/local
PROGRAM=<CHANGEME>
.PHONY: build clean install uninstall
bin/$(PROGRAM): src/*.go
go build -o bin/$(PROGRAM) src/*.go
build: bin/$(PROGRAM)
clean:
@rm -rf ./bin
install: bin/$(PROGRAM) uninstall
mkdir -p $(PREFIX)/bin
cp bin/$(PROGRAM) $(PREFIX)/bin/
cp systemd/$(PROGRAM).service /etc/systemd/system/
systemctl enable $(PROGRAM)
systemctl start $(PROGRAM)
sleep 0.5
systemctl status $(PROGRAM)
uninstall:
systemctl stop $(PROGRAM) 2>/dev/null | true
systemctl disable $(PROGRAM) 2>/dev/null | true
rm -f /etc/systemd/system/$(PROGRAM).service 2>/dev/null | true
rm -f $(PREFIX)/bin/$(PROGRAM) 2>/dev/null | true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment