#!/sbin/openrc-run
# Copyright 2016 Alpine Linux
# Distributed under the terms of the GNU General Public License v2
# $Id$

depend() {
	need net
}

start_pre() {
	checkpath -d -m 0775 -o $USER:$USER $PIDPATH
	checkpath -d -m 0775 -o $USER:$USER $LOGPATH
	checkpath -d -m 0775 -o $USER:$USER $ETCD_DATA_DIR
}

start() {
	ebegin "Starting $SVCNAME"
	start-stop-daemon --start \
		--pidfile "$PIDFILE" \
		--user $USER \
		--chdir "$ETCD_DATA_DIR" \
		--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"
}

