Last active
January 11, 2020 22:56
-
-
Save k14i/6473411 to your computer and use it in GitHub Desktop.
An /etc/init.d script for dropbox on Debian.
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
#!/usr/bin/env bash | |
# dropbox service | |
DROPBOX_USERS="" # space-separated usernames | |
DAEMON=.dropbox-dist/dropbox | |
NICE=19 # -20 - 19 | |
IONICE_CLASS=3 # 0 - 3 | |
IONICE_PRIOR=7 # 0 - 7 | |
KERNEL=`uname -s` | |
start() { | |
echo "Starting dropbox..." | |
for dbuser in $DROPBOX_USERS; do | |
HOMEDIR=`getent passwd $dbuser | cut -d: -f6` | |
if [ -x $HOMEDIR/$DAEMON ]; then | |
HOME="$HOMEDIR" | |
start-stop-daemon -b -o -c $dbuser -S -u $dbuser -x $HOMEDIR/$DAEMON | |
fi | |
done | |
while [ `pidof dropbox > /dev/null; echo $?` -ne 0 ]; do | |
sleep 0.1 | |
done | |
for pid in `pidof dropbox`; do | |
if [ `which renice > /dev/null; echo $?` -eq 0 ]; then | |
if [ x$KERNEL == xLinux ] || [ x$KERNEL == xDarwin ]; then | |
renice -n $NICE $pid | |
fi | |
fi | |
if [ `which ionice > /dev/null; echo $?` -eq 0 ]; then | |
if [ x$KERNEL == xLinux ]; then | |
ionice -c $IONICE_CLASS -n $IONICE_PRIOR -t -p $pid | |
fi | |
fi | |
done | |
} | |
stop() { | |
echo "Stopping dropbox..." | |
for dbuser in $DROPBOX_USERS; do | |
HOMEDIR=`getent passwd $dbuser | cut -d: -f6` | |
if [ -x $HOMEDIR/$DAEMON ]; then | |
start-stop-daemon -o -c $dbuser -K -u $dbuser -x $HOMEDIR/$DAEMON | |
fi | |
done | |
} | |
status() { | |
for dbuser in $DROPBOX_USERS; do | |
dbpid=`pgrep -u $dbuser dropbox` | |
if [ -z $dbpid ] ; then | |
echo "dropboxd for USER $dbuser: not running." | |
else | |
echo "dropboxd for USER $dbuser: 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/dropbox {start|stop|reload|force-reload|restart|status}" | |
exit 1 | |
esac | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment