Skip to content

Instantly share code, notes, and snippets.

@thisismitch
Forked from kbrnsr/dropbox
Last active March 26, 2018 02:13
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save thisismitch/6293d3f7f5fa37ca6eab to your computer and use it in GitHub Desktop.
Save thisismitch/6293d3f7f5fa37ca6eab to your computer and use it in GitHub Desktop.
Dropbox systemd and init files (CentOS 7)
#!/bin/sh
# To configure, add line with DROPBOX_USERS="user1 user2" to /etc/sysconfig/dropbox
# Probably should use a dropbox group in /etc/groups instead.
# Source function library.
. /etc/rc.d/init.d/functions
prog=dropboxd
lockfile=${LOCKFILE-/var/lock/subsys/$prog}
RETVAL=0
start() {
echo -n $"Starting $prog"
if [ -z $DROPBOX_USERS ] ; then
echo -n ": unconfigured: $config"
echo_failure
echo
rm -f ${lockfile} ${pidfile}
RETURN=6
return $RETVAL
fi
for dbuser in $DROPBOX_USERS; do
dbuser_home=`cat /etc/passwd | grep "^$dbuser:" | cut -d":" -f6`
daemon --user $dbuser /bin/sh -c "/opt/dropbox/dropboxd&"
done
RETVAL=$?
echo
[ $RETVAL = 0 ] && touch ${lockfile}
return $RETVAL
}
status() {
for dbuser in $DROPBOX_USERS; do
dbpid=`pgrep -u $dbuser dropboxd | grep -v grep`
if [ -z $dbpid ] ; then
echo "dropboxd for USER $dbuser: not running."
else
echo "dropboxd for USER $dbuser: running (pid $dbpid)"
fi
done
}
stop() {
echo -n $"Stopping $prog"
for dbuser in $DROPBOX_USERS; do
dbuser_home=`cat /etc/passwd | grep "^$dbuser:" | cut -d":" -f6`
killproc /opt/dropbox/dropboxd
done
RETVAL=$?
echo
[ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile}
}
# See how we were called.
case "$1" in
start)
start
;;
status)
status
;;
stop)
stop
;;
restart)
stop
start
;;
*)
echo $"Usage: $prog {start|status|stop|restart}"
RETVAL=3
esac
[Unit]
Description=Dropbox is a filesyncing sevice provided by dropbox.com. This service starts up the dropbox daemon.
After=network.target syslog.target
[Service]
Environment=LC_ALL=en_US.UTF-8
Environment=LANG=en_US.UTF-8
EnvironmentFile=-/etc/sysconfig/dropbox
ExecStart=/etc/init.d/dropbox start
ExecReload=/etc/init.d/dropbox restart
ExecStop=/etc/init.d/dropbox stop
Type=forking
[Install]
WantedBy=multi-user.target
@atesin
Copy link

atesin commented Mar 9, 2017

MULTIUSER SYSTEMD SCRIPT WITH NO WRAPPER

the following procedure does:

  • install the dropbox headless linux client daemon in its own folder
  • create and activate the multiuser systemd script (written by me)
  • create a local dropbox user
  • synchronize logons
  • install the service for that user
  • workaround for auto-update bug

su # be the super user
mkdir /opt/dropbox # create install subdirectory, ensure all parents has "+x" permissions
cd /opt/dropbox
curl -JLO https://www.dropbox.com/download?plat=lnx.x86_64 # or "lnx.x86" for 32-bit (wget redirections are bugged)
tar -xvzf dropbox-lnx.{version}.tar.gz # replace {version}
vi /etc/systemd/system/dropbox@.service # create systemd unit script as shown below

[Unit]
Description=Dropbox headless client daemon for user %i
Documentation=https://www.digitalocean.com/community/tutorials/how-to-install-dropbox-client-as-a-service-on-centos-7
After=network.target syslog.target

[Service]
User=%i
Environment=LC_ALL=en_US.UTF-8
Environment=LANG=en_US.UTF-8
ExecStart=/opt/dropbox/.dropbox-dist/dropboxd

[Install]
WantedBy=multi-user.target

systemctl daemon-reload # load new script
useradd dpbox-user # create local user
su dpbox-user
/opt/dropbox/.dropbox-dist/dropboxd # sinchronize dropbox account before enable daemon

# console message:

This pc is not linked to dropbox...
Visit https://www.dropbox.com/cli_link_nonce?nonce=XxXxXxX
...

# stay...

# open the shown link in another browser from any pc, login your dropbox account and press "Connect"
# when the console message changes, cancel the program (ctrl-c)

linked to dropbox, welcome {user}

exit # return to super user
systemctl enable dropbox@dpbox-user.service # enable and start dropbox for our user
systemctl start dropbox@dpbox-user.service

AUTO-UPDATE BUG WORKAROUND

suddenly a problem may occur that prevents starting dropbox, logs says something about KILL
i read somewhere that is due bugged auto-update client feature
supposedly it should be disabled (i dont think so)

you can update client manually to avoid this
or write an update script and cron it daily

#!/bin/bash

# config
DBXDIR=/opt/dropbox
DBXPLAT=lnx.x86_64

# begin
cd $DBXDIR
CURVER=dropbox-$DBXPLAT-$(/usr/bin/cat .dropbox-dist/VERSION).tar.gz
NEWVER=$(/usr/bin/curl -Is https://www.dropbox.com/download?plat=$DBXPLAT|/usr/bin/grep ^Location:)
NEWVER=${NEWVER##*-};NEWVER=dropbox-$DBXPLAT-${NEWVER%%[[:space:]]}

# new version already installed
if [ "$CURVER" == "$NEWVER" ];then exit 0;fi

#echo updating...
#exit

# downloading new version
/usr/bin/curl -Ls -o "$NEWVER" https://www.dropbox.com/download?plat=$DBXPLAT

# update and restart daemons
/usr/bin/systemctl stop dropbox@*
/usr/bin/mv .dropbox-dist ${CURVER}.d
/usr/bin/tar -xzf $NEWVER
/usr/bin/systemctl start dropbox@*

@piotr-dobrogost
Copy link

piotr-dobrogost commented Oct 18, 2017

@atesin

Nice, thanks for sharing.
I think manual step replace {version} could be replaced by downloading to specific file with -o <filename> option instead of -O-o, --output FILE Write to FILE instead of stdout

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