-
-
Save alexsavio/5508422 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# btsync service | |
# Replace with linux users you want to run BTSync clients for | |
BTSYNC_USERS="mendel" | |
DAEMON=/usr/bin/btsync | |
start() { | |
for btsuser in $BTSYNC_USERS; do | |
HOMEDIR=`getent passwd $btsuser | cut -d: -f6` | |
config=$HOMEDIR/.sync/config.json | |
if [ -f $config ]; then | |
echo "Starting BTSync for $btsuser" | |
start-stop-daemon -b -o -c $btsuser -S -u $btsuser -x $DAEMON -- --config $config | |
else | |
echo "Couldn't start BTSync for $btsuser (no $config found)" | |
fi | |
done | |
} | |
stop() { | |
for btsuser in $BTSYNC_USERS; do | |
dbpid=`pgrep -u $btsuser btsync` | |
if [ ! -z "$dbpid" ]; then | |
echo "Stopping btsync for $btsuser" | |
start-stop-daemon -o -c $btsuser -K -u $btsuser -x $DAEMON | |
fi | |
done | |
} | |
status() { | |
for btsuser in $BTSYNC_USERS; do | |
dbpid=`pgrep -u $btsuser btsync` | |
if [ -z "$dbpid" ]; then | |
echo "btsync for USER $btsuser: not running." | |
else | |
echo "btsync for USER $btsuser: running (pid $dbpid)" | |
fi | |
done | |
} | |
case "$1" in | |
start) | |
start | |
;; | |
stop) | |
stop | |
;; | |
restart|reload|force-reload) | |
stop | |
start | |
;; | |
status) | |
status | |
;; | |
*) | |
echo "Usage: /etc/init.d/btsync {start|stop|reload|force-reload|restart|status}" | |
exit 1 | |
esac | |
exit 0 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- Move btsync to /usr/bin or replace DAEMON with the absolute path to btsync | |
- Copy the script to /etc/init.d and chmod +x it | |
- Replace BTSYNC_USERS with a list of usernames that you want btsync to work with, space delimited | |
- Use rcconf or another tool to make the service btsync start at system initialization | |
- Execute service btsync start | |
- Create a directory named .sync in your home directory | |
- Create a file inside .sync named config.json with the dumped and modified configuration | |
- Replace the configuration entry "storage_path" with the path to the .sync directory | |
WHEN SETTING UP BTSYNC FOR MULTIPLE USERS, REMEMBER TO USE DIFFERENT PORT NUMBERS FOR webui.listen | |
- MULTIPLE PROCESSES CAN'T LISTEN TO THE SAME PORT! | |
Example: | |
{ | |
"device_name": "<DEVICE NAME>", | |
"listening_port": 0, | |
"storage_path": "/home/mendel/.sync", | |
"check_for_updates": true, | |
"use_upnp": true, | |
"download_limit": 0, | |
"upload_limit": 0, | |
"webui": { | |
"listen": "0.0.0.0:8888", | |
"login" : "admin", | |
"password" : "password" | |
}, | |
"shared_folders": [] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment