From 8176f6bf93c382dd1a9ca1d549d3a8213ef62f99 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Thu, 4 May 2017 14:14:33 -0400 Subject: add init script, systemd service file, Makefile for debug-me server installation Adapted from keysafe --- .gitignore | 1 + Makefile | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ debug-me.cabal | 6 +++++- debug-me.default | 2 ++ debug-me.init | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ debug-me.service | 18 ++++++++++++++++ 6 files changed, 149 insertions(+), 1 deletion(-) create mode 100644 Makefile create mode 100644 debug-me.default create mode 100644 debug-me.init create mode 100644 debug-me.service diff --git a/.gitignore b/.gitignore index b566711..3a34823 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ dist/* .stack-work/* +debug-me doc/.ikiwiki diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..ca07972 --- /dev/null +++ b/Makefile @@ -0,0 +1,62 @@ +# The install target will add this before all paths it writes to. +PREFIX?= + +# Can be "stack" or "cabal", or "./Setup" to build and use Setup.hs +BUILDER?=stack + +# Options to pass to the BUILDER. +# Using -j1 may result in a reproducible build. +BUILDEROPTIONS?= + +# Propigate flags through ghc to linker and compiler. +ghc_options=$(shell \ + for w in $(LDFLAGS); do \ + printf -- "-optl%s\n" "$$w"; \ + done; \ + for w in $(CFLAGS); do \ + printf -- "-optc%s\n" "$$w"; \ + done; \ + for w in $(CPPFLAGS); do \ + printf -- "-optc-Wp,%s\n" "$$w"; \ + done; \ + ) + +build: + rm -f debug-me + $(MAKE) debug-me + +debug-me: + if [ "$(BUILDER)" = ./Setup ]; then ghc --make Setup; fi + if [ "$(BUILDER)" = stack ]; then \ + $(BUILDER) build --ghc-options="$(ghc_options)" $(BUILDEROPTIONS); \ + else \ + $(BUILDER) configure --ghc-options="$(ghc_options)"; \ + $(BUILDER) build $(BUILDEROPTIONS); \ + fi + if [ "$(BUILDER)" = stack ]; then \ + ln -sf $$(find .stack-work/ -name debug-me -type f | grep build/debug-me/debug-me | tail -n 1) debug-me; \ + else \ + ln -sf dist/build/debug-me/debug-me debug-me; \ + fi + +clean: + if [ "$(BUILDER)" != ./Setup ] && [ "$(BUILDER)" != cabal ]; then $(BUILDER) clean; fi + rm -rf debug-me dist .stack-work Setup Setup.hi Setup.o + +install: install-files + useradd --system debug-me + chmod 700 $(PREFIX)/var/log/debug-me + chown debug-me:debug-me $(PREFIX)/var/log/debug-me + +install-files: debug-me + install -d $(PREFIX)/var/log/debug-me + install -d $(PREFIX)/usr/bin + install -s -m 0755 debug-me $(PREFIX)/usr/bin/debug-me + install -d $(PREFIX)/usr/share/man/man1 + install -m 0644 debug-me.1 $(PREFIX)/usr/share/man/man1/debug-me.1 + install -d $(PREFIX)/lib/systemd/system + install -m 0644 debug-me.service $(PREFIX)/lib/systemd/system/debug-me.service + install -d $(PREFIX)/etc/init.d + install -m 0755 debug-me.init $(PREFIX)/etc/init.d/debug-me + install -d $(PREFIX)/etc/default + install -m 0644 debug-me.default $(PREFIX)/etc/default/debug-me diff --git a/debug-me.cabal b/debug-me.cabal index c8fbb6d..383d61d 100644 --- a/debug-me.cabal +++ b/debug-me.cabal @@ -37,7 +37,11 @@ Extra-Source-Files: CHANGELOG INSTALL TODO + Makefile debug-me.1 + debug-me.service + debug-me.init + debug-me.default Executable debug-me Main-Is: debug-me.hs @@ -111,4 +115,4 @@ Executable debug-me source-repository head type: git - location: git://keysafe.branchable.com/ + location: git://debug-me.branchable.com/ diff --git a/debug-me.default b/debug-me.default new file mode 100644 index 0000000..866dd5e --- /dev/null +++ b/debug-me.default @@ -0,0 +1,2 @@ +# Parameters to pass to debug-me when it's started as a daemon. +DAEMON_PARAMS="--server /var/log/debug-me/ --delete-old-logs" diff --git a/debug-me.init b/debug-me.init new file mode 100644 index 0000000..fd11531 --- /dev/null +++ b/debug-me.init @@ -0,0 +1,61 @@ +#!/bin/sh + +### BEGIN INIT INFO +# Provides: debug-me +# Required-Start: $network $remote_fs +# Required-Stop: $network $remote_fs +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Short-Description: debug-me server +# Description: Starts debug-me in server mode +### END INIT INFO + +PATH=/bin:/usr/bin:/sbin:/usr/sbin +NAME=debug-me +DESC="debug-me server" +DAEMON="/usr/bin/debug-me" +PIDFILE=/var/run/"$NAME".pid + +test -x /usr/bin/debug-me || exit 0 + +. /lib/lsb/init-functions + +# Parameters to pass to debug-me. +# This can be overridden in /etc/default/debug-me +DAEMON_PARAMS="--server /var/log/debug-me/ --delete-old-logs" +if [ -e /etc/default/debug-me ]; then + . /etc/default/debug-me +fi + +case "$1" in + start) + log_daemon_msg "Starting $DESC" "$NAME" + start-stop-daemon --start --quiet --oknodo \ + --background --no-close \ + --pidfile "$PIDFILE" --make-pidfile \ + --chuid debug-me:debug-me \ + --exec "$DAEMON" -- $DAEMON_PARAMS \ + > /var/log/debug-me.log + log_end_msg $? + ;; + stop) + log_daemon_msg "Stopping $DESC" "$NAME" + killproc -p "$PIDFILE" "$DAEMON" + RETVAL=$? + [ $RETVAL -eq 0 ] && [ -e "$PIDFILE" ] && rm -f $PIDFILE + log_end_msg $RETVAL + ;; + restart|reload|force-reload) + log_daemon_msg "Restarting $DESC" "$NAME" + $0 stop + $0 start + ;; + status) + status_of_proc -p $PIDFILE "$DAEMON" "$NAME" && exit 0 || exit $? + ;; + *) + log_action_msg "Usage: /etc/init.d/debug-me {start|stop|status|restart|reload|force-reload}" + exit 2 + ;; +esac +exit 0 diff --git a/debug-me.service b/debug-me.service new file mode 100644 index 0000000..7b184c8 --- /dev/null +++ b/debug-me.service @@ -0,0 +1,18 @@ +[Unit] +Description=debug-me server +Documentation=https://debug-me.branchable.com/ + +[Service] +Environment='DAEMON_PARAMS=--server /var/log/debug-me/ --delete-old-logs' +EnvironmentFile=-/etc/default/debug-me +ExecStart=/usr/bin/debug-me $DAEMON_PARAMS +InaccessiblePaths=/home /etc +ReadWritePaths=/var/log/debug-me +User=debug-me +Group=debug-me +StandardInput=null +StandardOutput=journal +StandardError=journal + +[Install] +WantedBy=multi-user.target -- cgit v1.2.3