summary refs log tree commit diff stats
path: root/zsh/functions/runit/renamesv
blob: dba1098d453527c3b9ca0bbc60fc1e9bb90256cb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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