summaryrefslogtreecommitdiff
blob: 55760d7c3c5d53e62d948a3b390ea58002e1b577 (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
#!/sbin/openrc-run
# Copyright 1999-2014 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2

SVCNAME=etcd
PIDPATH=/var/run/${SVCNAME}
PIDFILE=${PIDPATH}/${SVCNAME}.pid
LOGPATH=/var/log/${SVCNAME}
DATADIR=/var/lib/${SVCNAME}
USER=$SVCNAME

depend() {
	need net
	need localmount
	after bootmisc
}

start() {
	if [ ! -d "$PIDPATH" ] ; then
		mkdir -p "$PIDPATH"
		chown $USER:$USER "$PIDPATH"
	fi
	if [ ! -d "$LOGPATH" ] ; then
		mkdir -p "$LOGPATH"
		chown $USER:$USER "$LOGPATH"
	fi
	if [ ! -d "$ETCD_DATA_DIR" ] ; then
		mkdir -p "$ETCD_DATA_DIR"
		chown $USER:$USER "$ETCD_DATA_DIR"
	fi

	ebegin "Starting $SVCNAME"
	start-stop-daemon --start \
		--pidfile "$PIDFILE" \
		--user $USER \
		--chdir "$ETCD_DATA_DIR" \
		-1 "$LOGPATH/$SVCNAME.log" \
		-2 "$LOGPATH/$SVCNAME.err" \
		--background \
		--make-pidfile \
		--exec /usr/bin/etcd -- \
			-name=$ETCD_NAME \
			-data-dir="$ETCD_DATA_DIR" \
			$ETCD_OPTS
	eend $? "Failed to start $SVCNAME"
}

stop() {
	ebegin "Stopping $SVCNAME"
	start-stop-daemon --stop --pidfile $PIDFILE
	eend $? "Failed to stop $SVCNAME"
	rm -f "$PIDFILE"
}