limenkad.openrc raw

   1  #!/sbin/openrc-run
   2  
   3  # backward compatibility for existing gentoo layout 
   4  #
   5  if [ -d "/var/lib/limenka/.limenka" ]; then
   6  	LIMENKAD_DEFAULT_DATADIR="/var/lib/limenka/.limenka"
   7  else
   8  	LIMENKAD_DEFAULT_DATADIR="/var/lib/limenkad"
   9  fi
  10  
  11  LIMENKAD_CONFIGFILE=${LIMENKAD_CONFIGFILE:-/etc/limenka/limenka.conf}
  12  LIMENKAD_PIDDIR=${LIMENKAD_PIDDIR:-/run/limenkad}
  13  LIMENKAD_PIDFILE=${LIMENKAD_PIDFILE:-${LIMENKAD_PIDDIR}/${SVCNAME}.pid}
  14  LIMENKAD_DATADIR=${LIMENKAD_DATADIR:-${LIMENKAD_DEFAULT_DATADIR}}
  15  LIMENKAD_LOGDIR=${LIMENKAD_LOGDIR:-/var/log/limenkad}
  16  LIMENKAD_USER=${LIMENKAD_USER:-${LIMENKA_USER:-limenka}}
  17  LIMENKAD_GROUP=${LIMENKAD_GROUP:-limenka}
  18  LIMENKAD_BIN=${LIMENKAD_BIN:-/usr/bin/limenkad}
  19  LIMENKAD_NICE=${LIMENKAD_NICE:-${NICELEVEL:-0}}
  20  LIMENKAD_OPTS="${LIMENKAD_OPTS:-${LIMENKA_OPTS}}"
  21  
  22  name="Limenka Knots daemon"
  23  description="Limenka cryptocurrency P2P network daemon"
  24  
  25  required_files="${LIMENKAD_CONFIGFILE}"
  26  pidfile="${LIMENKAD_PIDFILE}"
  27  in_background_fake="start"
  28  
  29  depend() {
  30  	need localmount net
  31  }
  32  
  33  # verify
  34  # 1) that the datadir exists and is writable (or create it)
  35  # 2) that a directory for the pid exists and is writable
  36  # 3) ownership and permissions on the config file
  37  start_pre() {
  38  	checkpath \
  39  	-d \
  40  	--mode 0750 \
  41  	--owner "${LIMENKAD_USER}:${LIMENKAD_GROUP}" \
  42  	"${LIMENKAD_DATADIR}"
  43  
  44  	checkpath \
  45  	-d \
  46  	--mode 0755 \
  47  	--owner "${LIMENKAD_USER}:${LIMENKAD_GROUP}" \
  48  	"${LIMENKAD_PIDDIR}"
  49  
  50  	checkpath -f \
  51  	-o "${LIMENKAD_USER}:${LIMENKAD_GROUP}" \
  52  	-m 0660 \
  53  	"${LIMENKAD_CONFIGFILE}"
  54  
  55  	checkpath -d --mode 0755 --owner "${LIMENKAD_USER}:${LIMENKAD_GROUP}" "${LIMENKAD_LOGDIR}"
  56  
  57  	checkconfig || return 1
  58  }
  59  
  60  start() {
  61  	ebegin "Starting ${name} in background"
  62  	mark_service_inactive
  63  	if start-stop-daemon \
  64  		--pidfile="${LIMENKAD_PIDFILE}" \
  65  		--chdir="${LIMENKAD_DATADIR}" \
  66  		--user="${LIMENKAD_USER}:${LIMENKAD_GROUP}" \
  67  		--nice="${LIMENKAD_NICE}" \
  68  		--exec="${LIMENKAD_BIN}" \
  69  		-- \
  70  		-pid="${LIMENKAD_PIDFILE}" \
  71  		-conf="${LIMENKAD_CONFIGFILE}" \
  72  		-datadir="${LIMENKAD_DATADIR}" \
  73  		-daemonwait \
  74  		-debuglogfile="${LIMENKAD_LOGDIR}/debug.log" \
  75  		-rpccookieperms=group \
  76  		${LIMENKAD_OPTS}
  77  	then
  78  		IN_BACKGROUND=yes rc-service "${SVCNAME}" --quiet start
  79  	else
  80  		rc-service "${SVCNAME}" --quiet zap
  81  	fi &
  82  }
  83  
  84  stop() {
  85  	ebegin "Stopping ${name}"
  86  	start-stop-daemon --stop \
  87  		--pidfile="${LIMENKAD_PIDFILE}" \
  88  		--retry="${LIMENKAD_SIGTERM_TIMEOUT}" \
  89  		--exec="${LIMENKAD_BIN}"
  90  	eend $?
  91  }
  92  
  93  checkconfig()
  94  {
  95  	if grep -qs '^rpcuser=' "${LIMENKAD_CONFIGFILE}" && \
  96  		! grep -qs '^rpcpassword=' "${LIMENKAD_CONFIGFILE}" ; then
  97  		eerror ""
  98  		eerror "ERROR: You must set a secure rpcpassword to run limenkad."
  99  		eerror "The setting must appear in ${LIMENKAD_CONFIGFILE}"
 100  		eerror ""
 101  		eerror "This password is security critical to securing wallets "
 102  		eerror "and must not be the same as the rpcuser setting."
 103  		eerror "You can generate a suitable random password using the following "
 104  		eerror "command from the shell:"
 105  		eerror ""
 106  		eerror "bash -c 'tr -dc a-zA-Z0-9 < /dev/urandom | head -c32 && echo'"
 107  		eerror ""
 108  		eerror "It is recommended that you also set alertnotify so you are "
 109  		eerror "notified of problems:"
 110  		eerror ""
 111  		eerror "ie: alertnotify=echo %%s | mail -s \"Limenka Alert\"" \
 112  			"admin@foo.com"
 113  		eerror ""
 114  		return 1
 115  	fi
 116  }
 117