Friday, 31 May 2013 09:46

CentOS init.d startup script for bittorrent sync btsync

#!/bin/sh
#
# chkconfig: - 27 73
# description: Starts and stops the btsync Bittorrent sync client
#         #
# pidfile: /var/run/bysync.pif
# config:  /etc/bitTorrentSync.cfg


# Source function library.
. /etc/rc.d/init.d/functions

# Avoid using root's TMPDIR
unset TMPDIR

# Source networking configuration.
. /etc/sysconfig/network

# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 1

# Check that smb.conf exists.
[ -f /etc/bitTorrentSync.cfg ] || exit 6


RETVAL=0

BTSYNCOPTIONS="--config /etc/bitTorrentSync.cfg"

start() {
        KIND="Bittorrentsync"
  echo -n $"Starting $KIND services: "
  daemon btsync "$BTSYNCOPTIONS"
  RETVAL=$?
  echo
  [ $RETVAL -eq 0 ] && touch /var/lock/subsys/btsync || RETVAL=1
  return $RETVAL
}  

stop() {
        echo
  KIND="Bittorrentsync"
  echo -n $"Shutting down $KIND services: "
  killproc btsync
  RETVAL=$?
  [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/btsync
  echo ""
  return $RETVAL
}  

restart() {
  stop
  start
}  

rhstatus() {
  status btsync
  return $?
}  

# Allow status as non-root.
if [ "$1" = status ]; then
       rhstatus
       exit $?
fi

case "$1" in
  start)
   start
  ;;
  stop)
    stop
  ;;
  restart)
    restart
  ;;
  reload)
    reload
  ;;
  status)
    rhstatus
  ;;
  condrestart)
    [ -f /var/lock/subsys/btsync ] && restart || :
  ;;
  *)
  echo $"Usage: $0 {start|stop|restart|reload|status|condrestart}"
  exit 2
esac

exit $?

Leave a comment

Make sure you enter all the required information, indicated by an asterisk (*). HTML code is not allowed.