summaryrefslogtreecommitdiffstats
path: root/src/dsc.sh
blob: 75457078c88389e4182d86ab8559ee0320f452aa (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
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#!/bin/sh

#
# dsc_enable=YES
# dsc_instances="node1 node2"
# 

. /etc/rc.subr

name="dsc"
rcvar=`set_rcvar`
load_rc_config $name

case "$dsc_enable" in
[Yy][Ee][Ss])
	;;
*)
	exit 0
esac

PIDDIR=/var/run
PREFIX=/usr/local/dsc

get_pid() {
	instance=$1
	if test -f $PIDDIR/dsc-$instance.pid ; then
		PID=`cat $PIDDIR/dsc-$instance.pid`
	else
		PID=''
	fi
}

do_status() {
	instance=$1
	if test ! -n "$PID" ; then
		echo "dsc-$instance is not running"
		false
	elif kill -0 $PID 2>/dev/null ; then
		echo "dsc-$instance is running as PID $PID"
	else
		echo "dsc-$instance is not running"
		false
	fi
}

do_start() {
	instance=$1
	if test -n "$PID" ; then
		if kill -0 $PID 2>/dev/null ; then
			echo "dsc-$instance is already running as PID $PID"
			true
			return
		fi
	fi
	if test -s $PREFIX/etc/dsc-$instance.conf ; then
		echo "Starting dsc-$instance"
		$PREFIX/bin/dsc $PREFIX/etc/dsc-$instance.conf
	else
		echo "$PREFIX/etc/dsc-$instance.conf not found"
		false
	fi
}

do_stop() {
	if test -n "$PID" ; then
		echo "Stopping dsc-$instance"
		kill -INT $PID
	else
		echo "dsc-$instance is not running"
		exit 0;
	fi
}


action=$1 ; shift

if test $# -eq 0 -a -n "$dsc_instances" ; then
	set $dsc_instances
fi

for instance ; do
    get_pid $instance
    case $action in
    start|faststart)
	do_start $instance
	;;
    stop)
	do_stop $instance
	;;
    restart)
	do_stop $instance
	do_start $instance
	;;
    status)
	do_status $instance
	;;
    *)
	echo "unknown action: $action"
	exit 1
	;;
    esac
done