Browse Source

Add systemd unit for rover

Douglas Thrift 5 years ago
parent
commit
40867a2bad
3 changed files with 28 additions and 0 deletions
  1. 17 0
      rover/dtrobots-rover.service
  2. 5 0
      rover/install.sh
  3. 6 0
      rover/main.go

+ 17 - 0
rover/dtrobots-rover.service

@@ -0,0 +1,17 @@
+[Unit]
+Description=Robot Rover
+Requires=network-online.target
+After=network-online.target
+
+[Service]
+User=robot
+Group=robot
+Restart=on-failure
+ExecStart=/home/robot/dtrobots/rover/rover -systemd
+KillSignal=SIGINT
+SuccessExitStatus=130
+
+[Install]
+WantedBy=multi-user.target
+
+# vim: filetype=systemd

+ 5 - 0
rover/install.sh

@@ -0,0 +1,5 @@
+#!/usr/bin/env bash
+
+cd $(dirname $0)
+go build
+sudo install -m 0644 -t /lib/systemd/system -v dtrobots-rover.service

+ 6 - 0
rover/main.go

@@ -19,6 +19,7 @@ func main() {
 		rightPort   string
 		rightDriver string
 		mode        driveMode
+		systemd     bool
 	)
 
 	flag.StringVar(&device, "gamepad", "/dev/input/event0", "the gamepad device path")
@@ -28,8 +29,13 @@ func main() {
 	flag.StringVar(&rightPort, "motor-right-port", "spi0.1:MB", "the right motor port")
 	flag.StringVar(&rightDriver, "motor-right-driver", "lego-nxt-motor", "the right motor driver")
 	flag.Var(&mode, "mode", "the drive mode (default \"tank\")")
+	flag.BoolVar(&systemd, "systemd", false, "do not include timestamps in log since systemd already does")
 	flag.Parse()
 
+	if systemd {
+		log.SetFlags(0)
+	}
+
 	g, err := gamepad.NewGamepad(device, gamepad.All)
 	if err != nil {
 		log.Fatalf("error creating gamepad: %v", err)