From e7657d6ba54ad5714657cff9be86ec416d342a4c Mon Sep 17 00:00:00 2001 From: Alan Pearce Date: Sun, 28 Apr 2013 20:54:18 +0100 Subject: Migrate repository from mercurial without history --- zsh/functions/runit/_sv | 7 +++++++ zsh/functions/runit/getservicedir | 2 ++ zsh/functions/runit/linksv | 16 ++++++++++++++++ zsh/functions/runit/renamesv | 36 ++++++++++++++++++++++++++++++++++++ 4 files changed, 61 insertions(+) create mode 100644 zsh/functions/runit/_sv create mode 100644 zsh/functions/runit/getservicedir create mode 100644 zsh/functions/runit/linksv create mode 100644 zsh/functions/runit/renamesv (limited to 'zsh/functions/runit') diff --git a/zsh/functions/runit/_sv b/zsh/functions/runit/_sv new file mode 100644 index 0000000..bf98b3e --- /dev/null +++ b/zsh/functions/runit/_sv @@ -0,0 +1,7 @@ +#compdef sv + +_arguments -A -S -s \ + '-v[wait up to 7 seconds for the command to take effect. (up|down|term|once|cont|exit)]' \ + '-w+[wait for %n seconds]: :_guard "[0-9]#" "numeric value"' \ + '1:command:(status up down once pause cont hup alarm interrupt quit 1 2 term kill exit start stop restart shutdown force-stop force-reload force-restart force-shutdown check)' \ + '*:installed service:_files -W ${SVDIR:-/service}' diff --git a/zsh/functions/runit/getservicedir b/zsh/functions/runit/getservicedir new file mode 100644 index 0000000..2e5d961 --- /dev/null +++ b/zsh/functions/runit/getservicedir @@ -0,0 +1,2 @@ +#!/usr/bin/env zsh +print ${$(readlink ${SVDIR:-/service}/$1):h} \ No newline at end of file diff --git a/zsh/functions/runit/linksv b/zsh/functions/runit/linksv new file mode 100644 index 0000000..7ee7109 --- /dev/null +++ b/zsh/functions/runit/linksv @@ -0,0 +1,16 @@ +#!/usr/bin/env zsh + +if [[ -z $1 ]]; then + echo "No service specified" + return 64 +fi + + +if [[ ! -x $1 ]]; then + echo "Service does not exist in current directory" + return 1 +fi + +mv $1{,.old} +ln -s =sv $1 +chmod -h a-w $1 diff --git a/zsh/functions/runit/renamesv b/zsh/functions/runit/renamesv new file mode 100644 index 0000000..dba1098 --- /dev/null +++ b/zsh/functions/runit/renamesv @@ -0,0 +1,36 @@ +#!/usr/bin/env zsh +local svdir=${SVDIR:-/service} +if [[ -z $1 || -z $2 ]]; then + echo "Usage: $0 source target" + return 64 +fi + +if [[ ! -h $svdir/$1 ]]; then + echo $svdir/$1 does not exist + return 2 +fi + +if [[ -e $svdir/$2 ]]; then + echo $svdir/$2 already exists + return 3 +fi + +local servicedir=`getservicedir` + +if [[ ! ( -w $svdir && -w $servicedir ) ]]; then + echo $svdir or $servicedir is not writeable +fi + +# The service doesn't have to be stopped as removing the link will do that +# However, running the same service twice isn't a great idea, so wait here +sv stop $1 + +rm -f $svdir/$1 || return + +mv $servicedir/{$1,$2} || return + +ln -s {$servicedir,$svdir}/$2 || return + +sv start $2 + +return -- cgit 1.4.1