"startproc -u USER" not working?

Hi,

I try to add a script for init.d to start “dropboxd” for 2 users.
The script works if it is started as user, MANUAL.
Now, I want to auto-start it after boot in runlevel 3 and 5 as a user, NOT as a root!

The system is used as a server.

How to proceed? “startproc -u USER” does not seem to start the deamon when I run the script as root.

server:/etc/rc.d # /sbin/startproc -u fire /home/fire/.dropbox-dist/dropboxd
server:/etc/rc.d # ./dropbox status
Checking for Dropbox daemon > PID...
                                                                               dead
server:/etc/rc.d # su fire
fire@server:/etc/rc.d> ./dropbox status
Checking for Dropbox daemon > PID...
                                                                               dead
fire@server:/etc/rc.d> /sbin/startproc -u fire /home/fire/.dropbox-dist/dropboxd
fire@server:/etc/rc.d> ./dropbox status
Checking for Dropbox daemon > PID... 4756
                                                                               running
firen@server:/etc/rc.d>     

Thanks in advance!

There are two variables being tested here: 1. whether startproc -u fire is starting the process as fire, and 2. whether dropbox status is reporting the right information. Don’t try to test two things at once. If you want to see if dropbox is running as fire, do:

ps aux | grep dropboxd

and you will see if it is running and as the right user.

pidof dropboxd

can also tell you if there is a dropboxd process active.

If the daemon is started correctly, then figure out why the status command doesn’t work. Probably because it’s expecting to see a pid file somewhere and that file isn’t created when the process is running as fire.

Not being able to create a pid file could also be a reason why dropboxd didn’t start. Then you have to fix the permissions of the location of the pid file.

Thanks, it is obvious I do not have enough programming experience to figure out the proper work breakdown.

Today (for me unknown why) the output is a bit different. I automagically do get an traceback message

** start as user **
fire@server:/etc/init.d> /sbin/startproc -u fire /home/fire/.dropbox-dist/dropboxd

fire@server:/etc/init.d> ps aux | grep dropbox
fire     4044  4.3  2.3 151148 24480 pts/0    Sl   19:54   0:01 /home/fire/.dropbox-dist/dropbox
fire     4096  0.0  0.0   3320   772 pts/0    R+   19:54   0:00 grep dropbox
fire@server:/etc/init.d> pidof dropbox
4044

fire@server:/etc/init.d>

** start as root **
server:/etc/init.d # /sbin/startproc -u fire /home/fire/.dropbox-dist/dropboxd
server:/etc/init.d # Traceback (most recent call last):
  File "__main__dropbox__.py", line 29, in <module>
  File "arch/__init__.py", line 29, in <module>
  File "core/preferences.py", line 237, in <module>
  File "core/preferences.py", line 141, in read
  File "core/client_model.py", line 142, in wrapped
  File "common_util/achub.py", line 30, in __enter__
  File "common_util/achub.py", line 105, in begin
  File "sqlobject/dbconnection.py", line 383, in transaction
  File "sqlobject/dbconnection.py", line 771, in __init__
  File "sqlobject/sqlite/sqliteconnection.py", line 117, in getConnection
  File "sqlobject/sqlite/sqliteconnection.py", line 161, in makeConnection
OperationalError: unable to open database file

server:/etc/init.d # ps aux | grep dropboxd
root      4334  0.0  0.0   3320   776 pts/0    R+   20:11   0:00 grep dropboxd
server:/etc/init.d # pidof dropboxd

server:/etc/init.d #   

There seems to be an permission issue for the deamon when it is started with “startproc -u”.
I fail to understand that, because the same command does work when logged on as user.

Well that “unable to open database file” is telling you something.

When you use startproc how does the daemon know where the database file is? Is its path mentioned in a configuration file? Is it assumed to be the in the current directory? If so maybe you need to cd to the correct directory before running startproc.

Similarly for any other files the daemon might need.

There may be some hidden assumptions when you are running it as a user that are false when you are running it from startproc.

I feel such a NOOB :\

It must be different if the daemon is started as user.

It is beyond my knowledge to alter the daemon, but “dropboxd” seams to be a very small bash script.

#!/bin/bash
PAR=$(dirname $(readlink -f ${BASH_SOURCE@]}))
OLD_LD_LIBRARY_PATH=$LD_LIBRARY_PATH
LD_LIBRARY_PATH=$PAR:$LD_LIBRARY_PATH
exec $PAR/dropbox $@

Is this causing my issue?

No, that’s just a wrapper, the real program seems to be a Python program started in the last line.

Well, I’m lost about what to do next.

Hopefully a working script for openSuSE will become available for this daemon soon >here<](http://wiki.dropbox.com/TipsAndTricks/TextBasedLinuxInstall)

It seems that dropboxd is sensitive to which directory it’s run from. If dropboxd reads a config file, where does it get it from? Can you specify it on the command line? What about any files that dropboxd, where are the pathnames specified, in the config file?

If I understand the “wrapper” right it makes sure the directories are set correct before the program is started.

The path where to start from is:
/home/fire/.dropbox-dist
It contains all the program files

The database, pid and host-file live in

server:/home/fire/.dropbox # ls
cache  command_socket  dropbox.db  dropbox.pid  host.db  iface_socket 

How can I find out if a config-file is used?

tail -f /var/log/messages > gives no output when I try to “startproc” the daemon.

I can ask you to install dropbox, but that would leave me with nothing to play lol!

That bash script just sets PAR to the directory containing the script and adds it to LD_LIBRARY_PATH, then runs the script.

I don’t think there is any problem running the script, since you did get a traceback from the Python program but it fails to open the database for whatever reason. That traceback isn’t very informative about whether it was the wrong filename or there were no permissions to open it. Perhaps it relies on the setting of $HOME or some other variable which is different if started from root.

Is there another way, like auto-login the users in a hidden terminal that starts the daemon and exit from the terminal when done?

Perhaps you could read the source where it throws and exception and maybe even modify it to display what’s wrong with the database pathname.

The file appears to be a non readable binary file. So that’s a nogo.

It was probably compiled from a Python source file.

… finally got it to run as USER from the root console

** run as root **
server:~ # su fire /bin/sh -c "/home/fire/.dropbox-dist/dropboxd&"
server:~ # pidof dropbox
5048
server:~ # ps aux | grep dropbox
fire     5048 12.2  2.3 151144 24476 pts/0    Sl   00:52   0:01 /home/fire/.dropbox-dist/dropbox
root      5094  0.0  0.0   3320   776 pts/0    R+   00:52   0:00 grep dropbox
server:~ #      

Now to translate it to a init script…

After all it was not “startproc” I had to use…
Thanks for the support ken_yap!

Here is my script for all who come across this thread:

#! /bin/sh
#
# Author: Fire@suse
#
# /etc/init.d/dropbox
#   and its symbolic link
#
#
### BEGIN INIT INFO
# Provides: dropboxd
# Required-Start: $network
# Should-Start:
# Required-Stop: $network
# Should-Stop:
# Default-Start: 3 5
# Default-Stop: 0 1 2 6
# Short-Description:    Startup script for dropbox daemon (online file storage & sync)
# Description:    Startup script for dropbox daemon (online file storage & sync)
### END INIT INFO

#USER1=fire
DROPBOX_USERS="user1 user2"

. /etc/rc.status
rc_reset

# Check for missing binary
for dbuser in $DROPBOX_USERS; do
	if  ! -x /home/$dbuser/.dropbox-dist/dropboxd ]; then
	echo -n >&2 "dropbox deamon, /home/$dbuser/.dropbox-dist/dropboxd is not installed. "
	rc_status -s
	exit 5
	fi
done


case "$1" in
	start)
		for dbuser in $DROPBOX_USERS; do
		echo -n "Starting dropbox daemon for $dbuser..."
		su $dbuser /bin/sh -c "/home/$dbuser/.dropbox-dist/dropboxd&"
		rc_status -v
		done
		;;
	stop)
		for dbuser in $DROPBOX_USERS; do
		echo -n "Stopping dropbox daemon for $dbuser..."
		/sbin/killproc /home/$dbuser/.dropbox-dist/dropbox
		rc_status -v
		done
		;;
	status)
		for dbuser in $DROPBOX_USERS; do
		echo -n "Checking dropbox daemon for $dbuser..."
		/sbin/checkproc /home/$dbuser/.dropbox-dist/dropbox
		rc_status -v
		done
		;;
	*)
		echo "Usage: $0 {start|stop|status|}"
		exit 1
		;;
esac
rc_exit

As root make a copy of the skeleton file in /etc/init.d and name it dropbox. Replace the content with the code above.

Replace user1 user2 by your own names. (As many as you like, but they all must be local users!)

Save it and run:

chkconfig --add dropbox

Thats all for openSuSE, enjoy!