fixed dogecoin init.d for 1.8, removed old versions
[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
5 PIDFILE="${DOGECOIN_DATADIR}/dogecoind.pid"
6
7 DOGECOIN_OPTS="-daemon -pid=${DOGECOIN_DATADIR}/dogecoind.pid -datadir=${DOGECOIN_DATADIR} ${DOGECOIN_OPTS}"
8
9 depend() {
10 need net
11 }
12
13 checkconfig() {
14 if [[ "${DOGECOIN_USERDIR}" == "" ]] ; then
15 eerror "Please edit /etc/conf.d/dogecoind"
16 eerror "A userdir must be specified."
17 return 1
18 fi
19
20 if [[ "${DOGECOIN_DATADIR}" == "" ]] ; then
21 eerror "Please edit /etc/conf.d/dogecoind"
22 eerror "A datadir must be specified."
23 return 1
24 fi
25
26 if [[ "${DOGECOIN_CONFFILE}" == "" ]] ; then
27 eerror "Please edit /etc/conf.d/dogecoind"
28 eerror "A conffile must be specified."
29 return 1
30 fi
31
32 if [[ "${DOGECOIN_USER}" == "" ]] ; then
33 eerror "Please edit /etc/conf.d/dogecoind"
34 eerror "A user must be specified to run dogecoind as that user."
35 eerror "Modify USER to your needs (you may also add a group after a colon)"
36 return 1
37 fi
38 if ! `getent passwd | cut -d ':' -f 1 | grep $( echo "${DOGECOIN_USER}" | cut -d ':' -f 1 ) -sq` ; then
39 eerror "Please edit /etc/conf.d/dogecoind"
40 eerror "Specified user must exist!"
41 return 1
42 fi
43 if `echo "${DOGECOIN_USER}" | grep ':' -sq` ; then
44 if ! `cut -d ':' -f 1 /etc/group | grep $( echo "${DOGECOIN_USER}" | cut -d ':' -f 2 ) -sq` ; then
45 eerror "Please edit /etc/conf.d/dogecoind"
46 eerror "Specified group must exist!"
47 return 1
48 fi
49 fi
50 if ! grep -q '^rpcpassword=' "${DOGECOIN_CONFFILE}"; then
51 eerror "Please edit `readlink -f ${DOGECOIN_CONFFILE}`"
52 eerror "There must be at least a line assigning rpcpassword=something-secure"
53 return 1
54 fi
55 if ! stat -Lc '%a' "${DOGECOIN_CONFFILE}" | grep -q '^[4567]00$'; then
56 eerror "`readlink -f ${DOGECOIN_CONFFILE}` should not be readable by other users"
57 return 1
58 fi
59 return 0
60 }
61
62 start() {
63 checkconfig || return 1
64 ebegin "Starting Dogecoind daemon"
65
66 pkg-config openrc
67 if [ $? = 0 ]; then
68 start_openrc
69 else
70 start_baselayout
71 fi
72 }
73
74 stop() {
75 ebegin "Stopping Dogecoin daemon"
76
77 pkg-config openrc
78 if [ $? = 0 ]; then
79 stop_openrc
80 else
81 stop_baselayout
82 fi
83 }
84
85 start_openrc() {
86 start-stop-daemon \
87 --start --user "${DOGECOIN_USER}" --name dogecoind \
88 --pidfile "${PIDFILE}" \
89 --env HOME="${DOGECOIN_USERDIR}" --exec /usr/bin/dogecoind \
90 --nicelevel "${NICELEVEL}" \
91 --wait 2000 \
92 -- ${DOGECOIN_OPTS}
93 eend $?
94 }
95
96 stop_openrc() {
97 start-stop-daemon --stop --user "${DOGECOIN_USER}" \
98 --name dogecoind --pidfile "${PIDFILE}" \
99 --wait 30000 \
100 --progress
101 eend $?
102 }
103
104 start_baselayout() {
105 start-stop-daemon \
106 --start --user "${DOGECOIN_USER}" --name dogecoind \
107 --pidfile "${PIDFILE}" \
108 --env HOME="${VARDIR}" --exec /usr/bin/dogecoind \
109 --chuid "${DOGECOIN_USER}" \
110 --nicelevel "${NICELEVEL}" \
111 -- ${DOGECOIN_OPTS}
112 eend $?
113 }
114
115 stop_baselayout() {
116 start-stop-daemon \
117 --stop \
118 --user "${DOGECOIN_USER}" \
119 --name dogecoind \
120 --pidfile "${PIDFILE}"
121 eend $?
122 }