net-p2p/dogecoind-1.5.1-r1
[portage-squeep] / net-p2p / dogecoind / files / dogecoin.initd
1 #!/sbin/runscript
2 # Distributed under the terms of the GNU General Public License, v2 or later
3
4 VARDIR="/var/lib/dogecoin"
5 CONFFILE="${VARDIR}/.dogecoin/dogecoin.conf"
6
7 depend() {
8 need net
9 }
10
11 checkconfig() {
12 if [[ "${DOGECOIN_USER}" == "" ]] ; then
13 eerror "Please edit /etc/conf.d/dogecoind"
14 eerror "A user must be specified to run dogecoind as that user."
15 eerror "Modify USER to your needs (you may also add a group after a colon)"
16 return 1
17 fi
18 if ! `getent passwd | cut -d ':' -f 1 | grep $( echo "${DOGECOIN_USER}" | cut -d ':' -f 1 ) -sq` ; then
19 eerror "Please edit /etc/conf.d/dogecoind"
20 eerror "Specified user must exist!"
21 return 1
22 fi
23 if `echo "${DOGECOIN_USER}" | grep ':' -sq` ; then
24 if ! `cut -d ':' -f 1 /etc/group | grep $( echo "${DOGECOIN_USER}" | cut -d ':' -f 2 ) -sq` ; then
25 eerror "Please edit /etc/conf.d/dogecoind"
26 eerror "Specified group must exist!"
27 return 1
28 fi
29 fi
30 if ! grep -q '^rpcpassword=' "${CONFFILE}"; then
31 eerror "Please edit `readlink -f ${CONFFILE}`"
32 eerror "There must be at least a line assigning rpcpassword=something-secure"
33 return 1
34 fi
35 if ! stat -Lc '%a' "${CONFFILE}" | grep -q '^[4567]00$'; then
36 eerror "`readlink -f ${CONFFILE}` should not be readable by other users"
37 return 1
38 fi
39 return 0
40 }
41
42 start() {
43 checkconfig || return 1
44 ebegin "Starting Dogecoind daemon"
45
46 pkg-config openrc
47 if [ $? = 0 ]; then
48 start_openrc
49 else
50 start_baselayout
51 fi
52 }
53
54 stop() {
55 ebegin "Stopping Dogecoin daemon"
56
57 pkg-config openrc
58 if [ $? = 0 ]; then
59 stop_openrc
60 else
61 stop_baselayout
62 fi
63 }
64
65 start_openrc() {
66 start-stop-daemon \
67 --start --user "${DOGECOIN_USER}" --name dogecoind \
68 --pidfile /var/run/dogecoind.pid --make-pidfile \
69 --env HOME="${VARDIR}" --exec /usr/bin/dogecoind \
70 --nicelevel "${NICELEVEL}" \
71 --background \
72 --wait 2000 \
73 -- ${DOGECOIN_OPTS}
74 eend $?
75 }
76
77 stop_openrc() {
78 start-stop-daemon --stop --user "${DOGECOIN_USER}" \
79 --name dogecoind --pidfile /var/run/dogecoind.pid \
80 --wait 30000 \
81 --progress
82 eend $?
83 }
84
85 start_baselayout() {
86 start-stop-daemon \
87 --start --user "${DOGECOIN_USER}" --name dogecoind \
88 --pidfile /var/run/dogecoind.pid --make-pidfile \
89 --env HOME="${VARDIR}" --exec /usr/bin/dogecoind \
90 --chuid "${DOGECOIN_USER}" \
91 --nicelevel "${NICELEVEL}" \
92 --background \
93 -- ${DOGECOIN_OPTS}
94 eend $?
95 }
96
97 stop_baselayout() {
98 start-stop-daemon \
99 --stop \
100 --user "${DOGECOIN_USER}" \
101 --name dogecoind \
102 --pidfile /var/run/dogecoind.pid
103 eend $?
104 }