Advertisement
Guest User

Untitled

a guest
Aug 28th, 2014
446
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.61 KB | None | 0 0
  1. #!/bin/sh -e
  2. ### BEGIN INIT INFO
  3. # Provides:     btsync
  4. # Required-Start:   $local_fs $remote_fs
  5. # Required-Stop:    $local_fs $remote_fs
  6. # Should-Start:     $network
  7. # Should-Stop:      $network
  8. # Default-Start:    2 3 4 5
  9. # Default-Stop:     0 1 6
  10. # Short-Description: Multi-user daemonized version of btsync.
  11. # Description: Starts the btsync daemon for all registered users.
  12. ### END INIT INFO
  13.  
  14. # Replace with linux users you want to run BTSync clients for
  15. BTSYNC_USERS="root"
  16. DAEMON=/opt/btsync
  17.  
  18. start() {
  19.   for btsuser in $BTSYNC_USERS; do
  20.     HOMEDIR=`getent passwd $btsuser | cut -d: -f6`
  21.     config=$HOMEDIR/.sync/config.json
  22.     if [ -f $config ]; then
  23.       echo "Starting BTSync for $btsuser"
  24.       start-stop-daemon -b -o -c $btsuser -S -u $btsuser -x $DAEMON -- --config $config
  25.     else
  26.       echo "Couldn't start BTSync for $btsuser (no $config found)"
  27.     fi
  28.   done
  29. }
  30.  
  31. stop() {
  32.   for btsuser in $BTSYNC_USERS; do
  33. #    dbpid=`pgrep -fu $btsuser $DAEMON`
  34. #    if [ ! -z "$dbpid" ]; then
  35. #      echo "Stopping btsync for $btsuser"
  36.       start-stop-daemon -o -c $btsuser -K -u $btsuser -x $DAEMON
  37. #    fi
  38.   done
  39. }
  40.  
  41. status() {
  42.   for btsuser in $BTSYNC_USERS; do
  43.     dbpid=`pgrep -fu $btsuser $DAEMON`
  44.     if [ -z "$dbpid" ]; then
  45.       echo "btsync for USER $btsuser: not running."
  46.     else
  47.       echo "btsync for USER $btsuser: running (pid $dbpid)"
  48.     fi
  49.   done
  50. }
  51.  
  52. case "$1" in
  53.  start)
  54. start
  55. ;;
  56. stop)
  57. stop
  58. ;;
  59. restart|reload|force-reload)
  60. stop
  61. start
  62. ;;
  63. status)
  64. status
  65. ;;
  66. *)
  67. echo "Usage: /etc/init.d/btsync {start|stop|reload|force-reload|restart|status}"
  68. exit 1
  69. esac
  70.  
  71. exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement