Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I have the following line in do_start() of my custom init script that starts a java application:

start-stop-daemon --background --start --quiet --oknodo --make-pidfile --pidfile $PIDFILE --chdir $SOLR_DIR --chuid $USER --exec $DAEMON -- \
$DAEMON_ARGS >>$LOG_DIR/$NAME.log 2>>$LOG_DIR/$NAME.err 

when expanded, becomes:

start-stop-daemon --background --start --quiet --oknodo --make-pidfile --pidfile /var/run/solr.pid 
--chdir /home/phuihock/src/proj/solr 
--chuid phuihock 
--exec /usr/bin/java 
-- -jar start.jar >>/home/phuihock/src/proj/logs/solr.log 2>>/home/phuihock/src/proj/logs/solr.err

The log files created are owned by user root, group root. I'd expect they are owned by the user I set with --chuid, because from the manpage, everything after -- are passed unmodified.

My question is, are all redirects from start-stop-daemon owned by root, and is there a way to change that?

share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

Redirections are not part of command line arguments. They are handled separately by the shell, which in your case is run as root. But even if the permissions were correct, this command wouldn't cause the output of the daemon to be appended to the log file.

For illustration, this is what actually happens:

  1. The shell executes start-stop-daemon and redirects its output to solr.log. The file is going to be empty, because this command doesn't output anything (just try running it manually, without redirection).
  2. The start-stop-daemon command processes its arguments and ends up calling /usr/bin/java -jar start.jar. Notice that there is no output redirection there, but the process is forked in the background, so the output ends up in /dev/null.

In other words, the daemon should either accept a log file argument, or you need to create a wrapper script that will handle the redirection. It might look as follows

#/bin/sh
cd /home/phuihock/src/proj/solr
exec /usr/bin/java -jar start.jar >> logs/solr.log
share|improve this answer
    
That solves the problem. Thanks! –  phuihock Apr 18 '11 at 4:45
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.