Browse Source

[podgrab] Use rc files for podgrab

Colin Powell 3 years ago
parent
commit
3310082415

+ 46 - 0
ansible/roles/podgrab/files/podgrab.rc

@@ -0,0 +1,46 @@
+#!/bin/sh
+# Start script for FreeBSD, contributed by user Fabian Abplanalp
+# Put this script in /usr/local/etc/rc.d then adjust PODGRAB_BIN and
+# PODGRAB_CFG values in /etc/defaults/podgrab
+
+export DATA="/var/podgrab"
+export CONFIG="/usr/local/src/podgrab"
+export GIN_MODE="release"
+export CHECK_FREQUENCY=240
+PODGRAB_BIN="/usr/local/bin/podgrab"
+PODGRAB_PID="/var/run/podgrab.pid"
+
+# Read configuration variable file if it is present
+[ -r /etc/defaults/podgrab ] && . /etc/defaults/podgrab
+
+case "$1" in
+"start")
+	echo "Starting podgrab..."
+	${PODGRAB_BIN} &
+	echo $! >${PODGRAB_PID}
+	echo "done"
+	;;
+
+"stop")
+	echo "Stopping podgrab..."
+	if [ -f ${PODGRAB_PID} ]; then
+		kill $(cat ${PODGRAB_PID})
+		rm ${PODGRAB_PID}
+		echo "done"
+	else
+		echo "not running?"
+	fi
+	;;
+
+"restart")
+	echo "Restarting podgrab..."
+	$0 stop
+	sleep 2
+	$0 start
+	;;
+
+*)
+	echo "$0 [start|stop|restart]"
+	;;
+
+esac

+ 2 - 2
ansible/roles/podgrab/handlers/main.yml

@@ -1,5 +1,5 @@
 ---
-- name: Supervisor restarted
+- name: Podgrab restarted
   service:
-    name: supervisord
+    name: podgrab
     state: restarted

+ 29 - 7
ansible/roles/podgrab/tasks/main.yml

@@ -3,9 +3,13 @@
   community.general.pkgng:
     name: git,go
     state: latest
+  tags:
+    - build
 
 - name: Source folder exists
   file: path=/usr/local/src mode=0755 state=directory
+  tags:
+    - build
 
 - name: Podgrab source deployed
   git:
@@ -13,16 +17,34 @@
     dest: /usr/local/src/podgrab
     accept_hostkey: yes
     update: yes
+  tags:
+    - build
+
+- name: Patch podgrab for jails
+  shell:
+    cmd: 'sed -i -e ''s/client\/*/\/usr\/local\/src\/podgrab\/client\//'' /usr/local/src/podgrab/main.go'
+    warn: false
+  tags:
+    - build
 
 - name: Build podgrab binary
   shell:
     chdir: /usr/local/src/podgrab
     cmd: go build .
+  tags:
+    - build
+
+- name: Podgrab rc file installed
+  ansible.builtin.copy:
+    src: podgrab.rc
+    dest: /usr/local/etc/rc.d/podgrab
+
+- name: Podgrab enabled
+  shell: sysrc podgrab_enable="YES"
 
-- name: Supervisor file installed
-  copy:
-    src: supervisor.conf
-    dest: /usr/local/etc/supervisor/conf.d/podgrab.conf
-    owner: root
-    mode: 0644
-  notify: Supervisor restarted
+- name: Install podgrab
+  ansible.builtin.copy:
+    src: /usr/local/src/podgrab/podgrab
+    dest: /usr/local/bin/podgrab
+    remote_src: yes
+  notify: Podgrab restarted