How to install and configure dropbox as a service on centos 7

Centos 7Linux

In this article, we will learn how to configure and install the Dropbox client and run as a service on CentOS7 server. This makes the server to connect with Dropbox and keep a copy of files synchronized. To complete the setup we needed a non-root user with Sudo permissions or a root user.

Installing the Dropbox Client

We can download the latest Linux Dropbox client from the below link.

# cd ~
# curl -Lo dropbox-linux-x86_64.tar.gz https://www.dropbox.com/download?plat=lnx.x86_64

After downloading, we need to create a folder for client software and extract the compressed file which we downloaded.

# mkdir -p /opt/dropbox-client
# tar xzfv dropbox-linux-x86_64.tar.gz --strip 1 -C /opt/dropbox-client

As the client is downloaded and extracted we needed to link the dropbox client account with the server.

Linking Dropbox Client

We needed to run the below command on the server in the folder where we want to store the Dropbox files.

# cd /usr/share/dropbox
# /opt/dropbox-client/dropboxd
# /opt/dropbox-client/dropboxd
This computer isn't linked to any Dropbox account...
Please visit https://www.dropbox.com/cli_link_nonce?nonce=9c4d26a095e82e2a0ca5e8029d66236f to link this device.

We needed to copy red colored link code and paste it on any browser.

Enter the credentials of your Dropbox account and save when we click on continue.

This computer is now linked to Dropbox. Welcome Chandra

As we can see that our Dropbox account is linked with the server, we can press Ctrl+C to quit the Dropbox command line box which we run to sync the account

Setting UP Service Script

We need to copy the below script and create these two files under /etc/init.d folder and /etc/systemd/system/dropbox.service for Centos 7

Below is the Code for Dropbox.service

# /etc/systemd/system/dropbox.service
[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=et/cini/t.ddropbo/x restart
ExecStop=et/cini/t.ddropbo/x stop
Type=forking
[Install]
WantedBy=multi-user.target

Below is the Code for Dropbox Service

# /etc/init.d/dropbox
#!/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
   fifor 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

Providing Execution Permission to Scripts

After that we needed to give execute permission to the script

# sudo chmod +x /etc/systemd/system/dropbox.service /etc/init.d/dropbox

We need to provide the script with the system users that will run the Dropbox.

# vi /etc/systemd/dropbox

Create the file with below lines

DROPBOX_USERS="Chandra"

We needed to start and enable them to start at boot time with the below commands

# systemctl daemon-reload
# systemctl start dropbox
# systemctl enable dropbox

Unlinking the Dropbox Account

To unlink the Dropbox Account we needed to stop the services

# service dropbox stop

The edit /etc/defaults/dropbox and remove the users from the list

# vi /etc/defaults/dropbox

Then delete the user’s Dropbox directory

# rm -rf /chandra/Dropbox

After this setup and configuration we are able to link the data which is stored on Dropbox and we can now link or unlink the Dropbox account to the server so that data can be backedup or synchronized to the Dropbox accounts.

raja
Published on 18-Oct-2019 11:04:52
Advertisements