StorjOld / dataserv-client

Client for storing and auditing data.
http://storj.io
MIT License
56 stars 24 forks source link

Linux system init script #213

Open Kidlike opened 8 years ago

Kidlike commented 8 years ago

I didn't know where to open this.

I have created an init script for dataserv-client (see below). It's not extremely sophisticated, but a decent starting point.

Since there are no linux packages, how should we distribute/share this?

/etc/init.d/dataserv-client

#! /bin/sh

### BEGIN INIT INFO
# Provides:     dataserv-client
# Default-Start:    3 4 5
# Default-Stop:     
# Short-Description:    storj
### END INIT INFO

set -e

test -x /usr/local/bin/dataserv-client || exit 0;
( /usr/local/bin/dataserv-client --help 2>&1 | grep -q 'Dataserve client' ) 2>/dev/null || exit 0

. /lib/lsb/init-functions
. /etc/default/dataserv-client

if [ -z "$DATASERV_OPTS" ]; then
    echo "No options found. Edit the file /etc/default/dataserv-client to set your options."
    exit 1;
fi

if [ -z "$DATASERV_LOGFILE" ]; then
    DATASERV_LOGFILE='/var/log/dataserv-client.log'
fi

case "$1" in
  start)
    log_daemon_msg "Starting Dataserve client" "dataserv-client" || true
    if start-stop-daemon --start --background --oknodo --pidfile /var/run/dataserv-client.pid --make-pidfile --exec /usr/local/bin/dataserv-client --no-close -- $DATASERV_OPTS >> $DATASERV_LOGFILE 2>&1; then
        log_end_msg 0 || true
    else
        log_end_msg 1 || true
    fi
    ;;
  stop)
    log_daemon_msg "Stopping Dataserve client" "dataserv-client" || true
    if start-stop-daemon --stop --quiet --oknodo --pidfile /var/run/dataserv-client.pid; then
        log_end_msg 0 || true
    else
        log_end_msg 1 || true
    fi
    ;;

  reload|force-reload)
    echo "Unsupported Operation"
    ;;

  restart)
    log_daemon_msg "Restarting Dataserve client" "dataserv-client" || true
    start-stop-daemon --stop --quiet --oknodo --retry 30 --pidfile /var/run/dataserv-client.pid
    if start-stop-daemon --start --background --oknodo --pidfile /var/run/dataserv-client.pid --make-pidfile --exec /usr/local/bin/dataserv-client --no-close -- $DATASERV_OPTS >> $DATASERV_LOGFILE 2>&1; then
        log_end_msg 0 || true
    else
        log_end_msg 1 || true
    fi
    ;;

  try-restart)
    echo "Unsupported Operation"
    ;;

  status)
    status_of_proc -p /var/run/dataserv-client.pid /usr/local/bin/dataserv-client dataserv-client && exit 0 || exit $?
    ;;

  *)
    log_action_msg "Usage: /etc/init.d/ssh {start|stop|restart|status}" || true
    exit 1
esac

exit 0

/etc/default/dataserv-client

# Default settings for dataserv-client. This file is sourced by /bin/sh from
# /etc/init.d/dataserv-client.

# Options to pass to dataserv-client
DATASERV_OPTS="--store_path=/media/storj --max_size=900G farm"
Kidlike commented 8 years ago

Just for reference, I used the following command to enable the autostart of this on ubuntu: update-rc.d dataserv-client start 20 3 4 5 . stop 20 0 1 6 .