-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathrunsvdir.sh
More file actions
executable file
·72 lines (63 loc) · 1.67 KB
/
Copy pathrunsvdir.sh
File metadata and controls
executable file
·72 lines (63 loc) · 1.67 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/env bash
exec 2>&1
if ! command -v realpath >/dev/null 2>&1
then
echo "You must install realpath to use this" >&2
exit 1
fi
me=${BASH_SOURCE[0]}
here=$(cd "$(dirname "$me")" && pwd)
real_here=$(realpath "$here")
root=$(cd "$real_here/.." && pwd)
cd "$root" || {
echo "Could not cd to $root" >&2
exit 1
}
if [ -z "$HOSTNAME" ]
then
echo "HOSTNAME not set, using $(hostname)" >&2
HOSTNAME=$(hostname)
else
echo "HOSTNAME is $HOSTNAME" >&2
fi
if [ -z "$SVDIR" ]
then
echo "SVDIR not set, finding the servicedir" >&2
service_root="$root/service"
servicedir="$service_root/generic"
first_level_host="${HOSTNAME%-*}"
second_level_host="${first_level_host%-*}"
prefix="${SV_PREFIX}"
if [ -d "$service_root/$HOSTNAME" ]
then
servicedir="$service_root/$HOSTNAME"
elif [ -d "$service_root/$first_level_host" ]
then
servicedir="$service_root/$first_level_host"
elif [ -d "$service_root/$second_level_host" ]
then
servicedir="$service_root/$second_level_host"
elif [ -d "$service_root/${prefix}${first_level_host}" ]
then
servicedir="$service_root/${prefix}${first_level_host}"
elif [ -d "$service_root/${prefix}${second_level_host}" ]
then
servicedir="$service_root/${prefix}${second_level_host}"
else
echo "No service directory found for $HOSTNAME" >&2
echo "Using $servicedir" >&2
fi
SVDIR="$servicedir"
else
servicedir="$SVDIR"
fi
if [ "$(id -u)" -eq 0 ]
then
ln -sf "$servicedir" /service
SVDIR="/service"
else
SVDIR="$servicedir"
fi
export SVDIR
echo "Starting runsvdir in $servicedir" >&2
exec runsvdir -P "$servicedir"