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 -- \

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?


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

cd /home/phuihock/src/proj/solr
exec /usr/bin/java -jar start.jar >> logs/solr.log

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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