You are not logged in.

#1 2009-02-13 20:08:08

brisbin33
Member
From: boston, ma
Registered: 2008-07-24
Posts: 1,796
Website

[SOLVED]custom rc.d script works... except at boot.

so i installed dropboxd in standalone mode (and even re-wrote the wiki section about it).

i also put together a nice rc.d script to start/stop the daemon very cleanly.  i thought it was working great b/c "/etc/rc.d/dropboxd {start|stop|restart}" works _perfectly_ while inside a running system.

however, putting dropboxd in my DAEMONS array in rc.conf causes funny things to happen.  sometimes i find it's running (via ps -A | grep dropboxd) but my files aren't synced, sometimes it's not running at all, but always -- when started by rc.conf at boot -- the /var/run/dropboxd.pid file doesn't get written (or get's written incorrectly), leading to a "kill [usage]" error the next time i shutdown or manually stop the daemon.

here's my rc.d script, maybe someone can review it?

#!/bin/bash

PATH=/usr/sbin:/usr/bin:/sbin:/bin
DESC="Dropbox file sharing service"
NAME=dropboxd
DAEMON=/home/patrick/.dropbox-dist/dropboxd
PIDFILE=/var/run/$NAME.pid

. /etc/rc.conf
. /etc/rc.d/functions

case "$1" in
  start)
    stat_busy "Starting dropbox service..."
    $DAEMON &
    if [ $? -gt 0 ]; then
      stat_fail
    else
      add_daemon $NAME
      pidof $NAME > $PIDFILE
      stat_done
    fi
    ;;
  stop)
    stat_busy "Stopping dropbox service..."
    if [ -a $PIDFILE ]; then
      PID=`cat $PIDFILE`
      kill $PID > /dev/null
      if [ $? -gt 0 ]; then
        stat_fail
      else
        rm $PIDFILE
        rm_daemon $NAME
        stat_done
      fi
    else
      pkill $NAME
      if [ $? -gt 0 ]; then
        stat_fail
      else
        stat_done
      fi
    fi
    ;;
  restart|force-reload)
    $0 stop
    sleep 1
    $0 start
    ;;
esac
exit 0

is possibly because i have "$DAEMON &" to start dropboxd in the backround (else it fails with "/etc/rc.d/dropboxd start") and i _also_ have "@dropboxd" in my DAEMONS array to start it in the background at boot? i'll remove the "@" and test while i wait to see if anyone replies here.

thanks in advance,
pat

Last edited by brisbin33 (2009-04-08 17:24:11)

Offline

#2 2009-02-13 23:11:28

ghostHack
Member
From: Bristol UK
Registered: 2008-02-29
Posts: 261

Re: [SOLVED]custom rc.d script works... except at boot.

Do you also have your network starting daemon backgrounded, eg @network, @net-profiles etc.  If so this could be why you see inconsistent results as the dropboxd daemon could be started before the network daemon has completly set up the network.

Offline

#3 2009-02-14 16:03:16

brisbin33
Member
From: boston, ma
Registered: 2008-07-24
Posts: 1,796
Website

Re: [SOLVED]custom rc.d script works... except at boot.

i start network non-backgrounded and first thing after syslog.  here's my full daemon array (as it was when i saw the bahavior).  i've since made dropboxd non background but i haven't had a chance to reboot yet (away for the weekend).

DAEMONS=(syslog-ng network sensors iptables hal @fcron @openntpd @alsa !xinetd @mysqld @sshd @vsftpd @samba @ushare @cups @dropboxd !icecast !mpd)

i've now made it:

DAEMONS=(syslog-ng network sensors iptables hal dropboxd @fcron @openntpd @alsa !xinetd @mysqld @sshd @vsftpd @samba @ushare @cups !icecast !mpd)

but haven't tested the reboot yet.

Offline

#4 2009-02-17 16:50:24

brisbin33
Member
From: boston, ma
Registered: 2008-07-24
Posts: 1,796
Website

Re: [SOLVED]custom rc.d script works... except at boot.

update/bump:

making dropboxd load in the foreground does not solve my problem.  i believe i've narrowed it down to the fact that /var/run/dropboxd.pid does not get populated when dropboxd is loaded at boot via rc.conf.  any ideas why this would happen?

edit: let me be more specific, when started at boot, dropboxd.pid is created but is empty.  when started via /etc/rc.d/dropboxd start while running; everything works as desired. /edit

fwiw:

sudo pidof dropboxd > /var/run/dropboxd.pid

results in permission denied; i need to become root via su - first, then create the .pid file.

doubt this has any relevancy, just seems like standard linux paranoid file permissions to me.

Last edited by brisbin33 (2009-02-17 16:54:10)

Offline

#5 2009-02-17 19:52:04

ghostHack
Member
From: Bristol UK
Registered: 2008-02-29
Posts: 261

Re: [SOLVED]custom rc.d script works... except at boot.

When you run '/etc/rc.d/dropboxd start' are you running it as your user or as root?  Looking at the website linked in the wiki entry sugests to me that the dropboxd binary needs to be run as the user but during the boot process all /etc/rc.* daemons are run as root.

If it does need to be run as the user then you might want to make the script run on user login rather than system boot.

Offline

#6 2009-02-17 20:24:33

brisbin33
Member
From: boston, ma
Registered: 2008-07-24
Posts: 1,796
Website

Re: [SOLVED]custom rc.d script works... except at boot.

apologies for not being explicit.  i always start/stop/restart dropboxd with sudo just like any other daemon.  i just now tested it by issuing su - first, then /etc/rc.d/dropboxd restart and it worked.  i don't see how that's any different that being started at boot. 

if the dropbox site mentions that the daemon should be started by normal user always, then i'll move it to rc.local...

edit, scratch that... that same dropbox site offers init script examples for redhat/debian/gentoo that i assume would be run as root at boot anyway.

i appreciate the help

Last edited by brisbin33 (2009-02-17 20:27:01)

Offline

#7 2009-02-17 20:42:38

brisbin33
Member
From: boston, ma
Registered: 2008-07-24
Posts: 1,796
Website

Re: [SOLVED]custom rc.d script works... except at boot.

update 2:

i recently found that i had left a dropboxd starting line in rc.local from before i wrote the rc.d script.  i thought this was causing problems and hoped removing it would solve everything.  it did not.

i removed the dropboxd line from rc.local and rebooted (leaving dropboxd in daemons array).

once in my system ps -A | grep dropbox shows it was not running; it was not started at boot.  and then this occured... there's got to be some syntax error in my script but i just can't figure it out... anyways, here's the series of [commandline] events:

> sudo /etc/rc.d/dropboxd start
:: Starting dropbox service...                                                             [DONE]
> cat /var/run/dropboxd.pid

> sudo /etc/rc.d/dropboxd restart
:: Stopping dropbox service...                                                             [BUSY] 
kill: usage: kill [-s sigspec | -n signum | -sigspec] pid | jobspec ... or kill -l [sigspec]
                                                                                           [FAIL]
:: Starting dropbox service...                                                             [DONE]
> cat /var/run/dropboxd.pid
5759 5709
> sudo /etc/rc.d/dropboxd restart
:: Stopping dropbox service...                                                             [BUSY] 
/etc/rc.d/dropboxd: line 28: kill: (5709) - No such process
                                                                                           [DONE]
:: Starting dropbox service...                                                             [DONE]
> cat /var/run/dropboxd.pid
5810
> sudo /etc/rc.d/dropboxd restart
:: Stopping dropbox service...                                                             [DONE]
:: Starting dropbox service...                                                             [DONE]
> cat /var/run/dropboxd.pid
5861
>

Last edited by brisbin33 (2009-02-17 20:50:10)

Offline

#8 2009-02-17 22:05:32

ghostHack
Member
From: Bristol UK
Registered: 2008-02-29
Posts: 261

Re: [SOLVED]custom rc.d script works... except at boot.

brisbin33 wrote:

apologies for not being explicit.  i always start/stop/restart dropboxd with sudo just like any other daemon.  i just now tested it by issuing su - first, then /etc/rc.d/dropboxd restart and it worked.  i don't see how that's any different that being started at boot. 

if the dropbox site mentions that the daemon should be started by normal user always, then i'll move it to rc.local...

edit, scratch that... that same dropbox site offers init script examples for redhat/debian/gentoo that i assume would be run as root at boot anyway.

i appreciate the help

Those scripts would be run as root but they start the dropboxd binary for each of a specified list of users.  e.g. the Fedora/Redhat script has

DROPBOX_USERS="user1 user2" 

prog=dropboxd
lockfile=${LOCKFILE-/var/lock/subsys/dropbox}
RETVAL=0

start() {
        echo -n $"Starting $prog"
        for dbuser in $DROPBOX_USERS; do
            daemon --user $dbuser /home/$dbuser/.dropbox-dist/dropboxd 
        done

        RETVAL=$?
        echo
        [ $RETVAL = 0 ] && touch ${lockfile}
        return $RETVAL
}

so you could try changing your '$DAEMON &' line to 'su - patrick $DAEMON &'

One other thing I noticed is that the redhat/debian/gentoo init scripts don't have the '&' but its been a while since I used a sys-v init system so I'm not sure if its significant.

Offline

#9 2009-02-17 22:07:25

brisbin33
Member
From: boston, ma
Registered: 2008-07-24
Posts: 1,796
Website

Re: [SOLVED]custom rc.d script works... except at boot.

thank you ghostHack, i will try with su - patrick as that's a simple fix.  i originally wrote it without the & but it would just fail in all cases that way.  backgrounding the daemon fixed that.

edit: ok su - patrick is a bit tricky as i need to become root again to finish the script.  logout doesn't work, exit doesn't work and su - doesn't work.  i'll continue work on this.

thanks.

Last edited by brisbin33 (2009-02-17 22:13:13)

Offline

#10 2009-02-17 22:28:08

brisbin33
Member
From: boston, ma
Registered: 2008-07-24
Posts: 1,796
Website

Re: [SOLVED]custom rc.d script works... except at boot.

alright, i'm a dumb dummy.  because the daemon was being started in the background the next command, pidof was being run too soon and not getting the pid.  i changed it to:

sleep 3 && pidof $NAME > $PIDFILE

the daemon is background in rc.conf so it doesnt cost me any boot time smile

on first reboot this seems to have fixed it.  i don't know why it's different at boot vs when the system's already up but oh well.  in my mind, it's solved.

EDIT: grrrrrr, nevermind.   now it works at boot but not with sudo /etc/rc.d/dropboxd start/stop/whatever.  this is really annoying.

Last edited by brisbin33 (2009-02-17 22:42:27)

Offline

#11 2009-02-17 23:21:07

ghostHack
Member
From: Bristol UK
Registered: 2008-02-29
Posts: 261

Re: [SOLVED]custom rc.d script works... except at boot.

brisbin33 wrote:

edit: ok su - patrick is a bit tricky as i need to become root again to finish the script.  logout doesn't work, exit doesn't work and su - doesn't work.  i'll continue work on this.
thanks.

Sorry, my fault :rolleyes: obviously we don't want to start a login shell in the middle of the script, I think it should be

su -c "$DAEMON &" patrick
# or 
su -c "$DAEMON" patrick

On the other issue, from looking at the pidof man page I think you want the line to be pidof $DAEMON > $PIDFILE

pidof man page wrote:

When  pidof  is invoked with a full pathname to the program it should find the pid of,
it is reasonably safe.  Otherwise it is possible that it returns pids of running programs that happen to have
the same name as the program you're after but are actually other programs.

Whether this will solve the problem I'm not sure but this will make certain that you get the pid of /home/patrick/.dropbox-dist/dropboxd if it is running rather than some other process which has dropboxd in its name (which I've just realised would include your /etc/rc.d/dropboxd script).
The sleep may still be needed though which is not ideal.

Offline

#12 2009-02-18 14:27:02

brisbin33
Member
From: boston, ma
Registered: 2008-07-24
Posts: 1,796
Website

Re: [SOLVED]custom rc.d script works... except at boot.

ghostHack wrote:

which I've just realised would include your /etc/rc.d/dropboxd script

this makes sense to me considering i was getting two pids in the .pid file in some cases (it's all about timing it seems).  i've made your change and it works with /etc/rc.d/dropboxd restart.  i'll test the reboot soon (i need the ssh tunnel right now) and report back.

Offline

#13 2009-02-19 02:44:32

brisbin33
Member
From: boston, ma
Registered: 2008-07-24
Posts: 1,796
Website

Re: [SOLVED]custom rc.d script works... except at boot.

no dice... i still end up with an empty /var/run/dropboxd.pid file after rebooting.  for the time being i've ditched the rc.d script and moved to an rc.local approach... maybe i'll come back to it some day.

thanks for the help so far.

Offline

#14 2009-04-08 17:23:57

brisbin33
Member
From: boston, ma
Registered: 2008-07-24
Posts: 1,796
Website

Re: [SOLVED]custom rc.d script works... except at boot.

ok, old thread but i _finally_ got to the bottom of it.

even though the process is always started as /home/username/.dropbox-dist/dropboxd, i actually noticed the other day that in htop it was showing as /home/username/.dropbox-dist/dropbox (no D on the end).  so the line in my rc.d script that gets the PID was failing, dropped the D off the end and everything works flawlessly.

oh well, dumb mistakes.  the wiki's been updated too.  marked solved.

Offline

Board footer

Powered by FluxBB