Skip to content

Instantly share code, notes, and snippets.

@k14i
Last active December 22, 2015 12:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save k14i/6473395 to your computer and use it in GitHub Desktop.
Save k14i/6473395 to your computer and use it in GitHub Desktop.
An /etc/init.d script for dropbox on RHEL.
#!/usr/bin/env bash
# chkconfig: 345 85 1
# description: Startup script for dropbox daemon
#
# processname: dropboxd
# pidfile: /var/run/dropbox.pid
# config: /etc/sysconfig/dropbox
#
### BEGIN INIT INFO
# Provides: dropboxd
# Required-Start: $local_fs $network $syslog
# Required-Stop: $local_fs $syslog
# Should-Start: $syslog
# Should-Stop: $network $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start up the Dropbox file syncing daemon
# Description: Dropbox is a filesyncing sevice provided by dropbox.com
# This service starts up the dropbox daemon.
### END INIT INFO
NICE=19 # -20 - 19
IONICE_CLASS=3 # 0 - 3
IONICE_PRIOR=7 # 0 - 7
KERNEL=`uname -s`
# Source function library.
. /etc/rc.d/init.d/functions
# To configure, add line with DROPBOX_USERS="user1 user2" to /etc/sysconfig/dropbox
# Probably should use a dropbox group in /etc/groups instead.
[ -f /etc/sysconfig/dropbox ] && . /etc/sysconfig/dropbox
prog=dropboxd
lockfile=${LOCKFILE-/var/lock/subsys/$prog}
config=${CONFIG-/etc/sysconfig/dropbox}
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
daemon --user $dbuser /bin/sh -c "/home/$dbuser/.dropbox-dist/dropboxd&"
done
RETVAL=$?
echo
[ $RETVAL = 0 ] && touch ${lockfile}
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
return $RETVAL
}
status() {
for dbuser in $DROPBOX_USERS; do
dbpid=`pgrep -u $dbuser dropbox | 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
killproc /home/$dbuser/.dropbox-dist/dropbox
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
exit $RETVAL
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment