Skip to content

Instantly share code, notes, and snippets.

@brandonb927
Last active February 22, 2022 01:25
Show Gist options
  • Star 11 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save brandonb927/a0b33ecbe6fa8337b0b4 to your computer and use it in GitHub Desktop.
Save brandonb927/a0b33ecbe6fa8337b0b4 to your computer and use it in GitHub Desktop.
Dropbox init.d script for Ubuntu 14.04 Server LTS - Dropbox has (recently) changed the CLI daemon from `dropbox` to `dropboxd`.
#!/bin/sh
# Usernames who will be using the Dropbox service
DROPBOX_USERS="username"
DAEMON=.dropbox-dist/dropboxd
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
}
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 -p $HOMEDIR/.dropbox/dropbox.pid
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
@jzaruba
Copy link

jzaruba commented May 10, 2016

Hello

When running this script on Ubuntu 14.04.4 LTS following command
/etc/init.d/dropbox status
yields following error:
/etc/init.d/dropbox: 51: [: 302: unexpected operator
dropboxd for USER root: running (pid 302
667)

When dropbox is NOT running, following command:
/etc/init.d/dropbox status
says:
dropboxd for USER root: running (pid 683)
INCORRECT :(

When running with bash:
bash /etc/init.d/dropbox status
I get correct status:
dropboxd for USER root: not running.
CORRECT

is this script actually intended for sh?
I am not familiar with this stuff but according to Stackoverflow.com it would appear that the syntax is rather bash.

@brandonb927
Copy link
Author

@jzaruba this script is definitely just copy-paste from their docs from a year or two ago

@fishcorn
Copy link

You should check out this update here: https://gist.github.com/jaygooby/2948647#gistcomment-1269833

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment