net-p2p/dogecoind-1.5.1-r1
[portage-squeep] / net-p2p / dogecoind / files / dogecoin.initd
diff --git a/net-p2p/dogecoind/files/dogecoin.initd b/net-p2p/dogecoind/files/dogecoin.initd
new file mode 100644 (file)
index 0000000..c315843
--- /dev/null
@@ -0,0 +1,104 @@
+#!/sbin/runscript
+# Distributed under the terms of the GNU General Public License, v2 or later
+
+VARDIR="/var/lib/dogecoin"
+CONFFILE="${VARDIR}/.dogecoin/dogecoin.conf"
+
+depend() {
+       need net
+}
+
+checkconfig() {
+       if [[ "${DOGECOIN_USER}" == "" ]] ; then
+               eerror "Please edit /etc/conf.d/dogecoind"
+               eerror "A user must be specified to run dogecoind as that user."
+               eerror "Modify USER to your needs (you may also add a group after a colon)"
+               return 1
+       fi
+       if ! `getent passwd | cut -d ':' -f 1 | grep $( echo "${DOGECOIN_USER}" | cut -d ':' -f 1 ) -sq` ; then
+               eerror "Please edit /etc/conf.d/dogecoind"
+               eerror "Specified user must exist!"
+               return 1
+       fi
+       if `echo "${DOGECOIN_USER}" | grep ':' -sq` ; then
+               if ! `cut -d ':' -f 1 /etc/group | grep $( echo "${DOGECOIN_USER}" | cut -d ':' -f 2 ) -sq` ; then
+                       eerror "Please edit /etc/conf.d/dogecoind"
+                       eerror "Specified group must exist!"
+                       return 1
+               fi
+       fi
+       if ! grep -q '^rpcpassword=' "${CONFFILE}"; then
+               eerror "Please edit `readlink -f ${CONFFILE}`"
+               eerror "There must be at least a line assigning rpcpassword=something-secure"
+               return 1
+       fi
+       if ! stat -Lc '%a' "${CONFFILE}" | grep -q '^[4567]00$'; then
+               eerror "`readlink -f ${CONFFILE}` should not be readable by other users"
+               return 1
+       fi
+       return 0
+}
+
+start() {
+       checkconfig || return 1
+       ebegin "Starting Dogecoind daemon"
+
+       pkg-config openrc
+       if [ $? = 0 ]; then
+          start_openrc
+       else
+          start_baselayout
+       fi
+}
+
+stop() {
+       ebegin "Stopping Dogecoin daemon"
+
+       pkg-config openrc
+       if [ $? = 0 ]; then
+          stop_openrc
+       else
+          stop_baselayout
+       fi
+}
+
+start_openrc() {
+       start-stop-daemon \
+       --start --user "${DOGECOIN_USER}" --name dogecoind \
+       --pidfile /var/run/dogecoind.pid --make-pidfile \
+       --env HOME="${VARDIR}" --exec /usr/bin/dogecoind \
+       --nicelevel "${NICELEVEL}" \
+       --background \
+       --wait 2000 \
+       -- ${DOGECOIN_OPTS}
+       eend $?
+}
+
+stop_openrc() {
+       start-stop-daemon --stop --user "${DOGECOIN_USER}" \
+       --name dogecoind --pidfile /var/run/dogecoind.pid \
+       --wait 30000 \
+       --progress
+       eend $?
+}
+
+start_baselayout() {
+       start-stop-daemon \
+       --start --user "${DOGECOIN_USER}" --name dogecoind \
+       --pidfile /var/run/dogecoind.pid --make-pidfile \
+       --env HOME="${VARDIR}" --exec /usr/bin/dogecoind \
+       --chuid "${DOGECOIN_USER}" \
+       --nicelevel "${NICELEVEL}" \
+       --background \
+       -- ${DOGECOIN_OPTS}
+       eend $?
+}
+
+stop_baselayout() {
+       start-stop-daemon \
+       --stop \
+       --user "${DOGECOIN_USER}" \
+       --name dogecoind \
+       --pidfile /var/run/dogecoind.pid
+       eend $?
+}