Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

My question is, how can I modify the script so that it will tell me what goes wrong?

The scenario is this: I'm trying to get Sonatype Nexus to start as a service in Ubuntu 10.04, and it just will not work.

(I'm not looking for help on how to run Nexus, but on how to get some useful output from a script)

It works when invoking it with

sudo /etc/init.d/nexus start

but fails when using

sudo service nexus start

I have run the update-rc.d command on it, and done everything according to instructions.

The nexus init.d-script has a point where it calls itself when it detects that it should run as another user ('nexus'):

su -m $RUN_AS_USER -c "\"$REALPATH\" $2"

which expands to

su -m nexus -c '"/opt/nexus-2.0.2/bin/jsw/linux-x86-64/nexus" start'

when adding the -x debug flag to the script. This command results in return code 1. It never executes - I've set -x debug flag on the script, placed echo commands with redirect to file at the start of script to trace, etc.

I cannot get any output telling me why the command will not execute. I've tried appending redirect to file after the above script line, inside the quotes, outside, any way I could imagine. All info I can get is by inserting a line

echo $?

after the su line, which outputs '1'.

Is there a way I can see what happens when the su command runs?

share|improve this question
su - USER -c "commands" Why are you using -m? su -m USER... – user60449 May 4 '12 at 17:37
You say it never executes (when you use set -x), so it fails at an earlier stage? could you provide the xtrace output perhaps? – geirha Jun 27 '12 at 10:09

It could be that the user wasn't set up as system user correctly. (Don't use the adduser command for that.) Try to delete user nexus and re-add it.

sudo groupadd nexus
sudo useradd -r -g nexus nexus

Don't forget to chown the home of the nexus binaries and the sonatype-work directory and also the directory where the script puts the PID file to the new user.

share|improve this answer
Why not just add nexus to nexus with sudo usermod -a -G nexus nexus? – Eliah Kagan Jun 27 '12 at 8:59
Better to use adduser than useradd. It has a --system option for creating system users. – geirha Jun 27 '12 at 10:03

I had this problem when I locked down the nexus user to use /bin/false as it's shell. Because this part of the script executes a shell command passed to su as an argument, this caused the script to just exit right there.

share|improve this answer

Your Answer


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.