1
votes

I wrote a script as Ubuntu startup service (that located at /etc/init.d and run at startup) There is a line

HOMEDIR=`getent passwd username1 | cut -d: -f6`

The problem is, when I run the script in shell, being logged as username1 or even root, the command returns

/home/username1

When the script is run on boot, the command returns nothing. Why that happens? Maybe, the user (or super one) does not have access to the /usr/bin/passwd file?

UPDATE: The problem is username1 is stored in remote server, so LDAP loads it while boot. When the command, referred to above, executes, LDAP status is activating (start) but not active (running). It seems to be that since it is not started completely, so username1 account is not loaded to the host system.

Still I failed to decide problem, now I'm trying, any help/hints appreciated.

1

1 Answers

0
votes

The problem solved!

This is a fixed script containing the line concerning the question (this script serves dropbox daemon start | stop):

#!/bin/sh
# dropbox service
# Replace with linux users you want to run Dropbox clients for

### BEGIN INIT INFO
# Provides: dropbox
# Required-Start: $local_fs $remote_fs $network $syslog $named slapd
# Required-Stop: $local_fs $remote_fs $network $syslog $named
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# X-Interactive: false
# Short-Description: dropbox service
### END INIT INFO
sleep 10s
DROPBOX_USERS="username1"
DAEMON=.dropbox-dist/dropboxd
start() {
 echo "Starting dropbox..."
 for dbuser in $DROPBOX_USERS; do
 HOMEDIR=`getent passwd $dbuser | cut -d: -f6`
 if [ -x $HOMEDIR/$DAEMON ]; then
 HOME="$HOMEDIR" start-stop-daemon -b -o -c $dbuser -S -x $HOMEDIR/$DAEMON &> /dev/null
 fi
 done
}

stop() {
 echo "Stopping dropbox..."
 for dbuser in $DROPBOX_USERS; do
 HOMEDIR=`getent passwd $dbuser | cut -d: -f6`
 if [ -x $HOMEDIR/$DAEMON ]; then
 /sbin/start-stop-daemon -o -c $dbuser -K -u $dbuser -x $HOMEDIR/$DAEMON
 fi
 done
}

status() {
 for dbuser in $DROPBOX_USERS; do
 dbpid=`pgrep -u $dbuser dropbox`
 if [ -z $dbpid ] ; then
 echo "dropboxd for USER $dbuser: not running."
 else
 echo "dropboxd for USER $dbuser: running (pid $dbpid)"
 fi
 done
}

case "$1" in
 start)
 start
 ;;
 stop)
 stop
 ;;
 restart|reload|force-reload)
 stop
 start
 ;;
 status)
 status
 ;;
 *)
 echo "Usage: /etc/init.d/dropbox {start|stop|reload|force-reload|restart|status}"
 exit 1
 esac

exit 0

As I discovered, the script needs LDAP server to be started, so in the line 7 I added slapd after $named facility:

# Required-Start: $local_fs $remote_fs $network $syslog $named slapd

where slapd is the service for LDAP, provided in the file /etc/init.d/slapd, it is decribed in line 3 (init info block):

# Provides:          slapd

So, after I added it, I succeeded with running dropbox at startup in 50% of cases. So I added a hack:

sleep 10s

Now it works properly.