Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Upstart console output not working

I used Upstart's provided example for console output.

/etc/init/test.conf

console output

pre-start script

  # Perform whatever checks you like here (maybe checking
  # '/etc/default/foo' to see if the service is enabled # or not).
  #
  # if there are no problems detected, simply "exit 0", else do
  # something like this...

  # display an error message to stderr *on the console* and also write
  # the same message to the system log.
  logger -is -t "$UPSTART_JOB" "ERROR: foo!"

  # tell Upstart not to start the main process for the job.
  exit 1
end script

# this service doesn't do much :-)
exec sleep 999

And then as root

$ initctl start test
initctl: Job failed to start

The message is present in /var/log/syslog, but the message was not present in the console.

Jul 23 07:42:19 paul test[26595]: ERROR: foo!

How can I log errors to the console?

This is Ubuntu 14.04,

$ initctl version
init (upstart 1.12.1)
like image 254
Paul Draper Avatar asked Jul 23 '16 13:07

Paul Draper


1 Answers

console output writes to /dev/console, which, by default, is the system virtual logging device: it's not going to write to your personal console (e.g. /dev/tty0).

You can actually test the difference in behavior if you attempt to write directly to these virtual devices:

sudo echo test >> /dev/console     # Won't work
sudo su; echo test >> /dev/console # Works but nothing prints
sudo echo test >> /dev/tty0        # Works and prints

For more on the differences between the different virtual console devices, see this Unix StackExchange question.

If you really want, you can change what /dev/console points to by modifying your boot configuration:

# /etc/default/grub

# If you change this file, run 'update-grub' afterwards to update
# /boot/grub/grub.cfg.

GRUB_CMDLINE_LINUX="console=tty0 console=ttyS0,115200n8"

...but if I were you, I'd just use the console log stanza instead of console output and then tail the generated file.

like image 55
fny Avatar answered Nov 15 '22 06:11

fny