Upstart控制台输出无法正常工作

时间:2016-07-23 13:45:16

标签: logging console upstart

我使用了Upstart提供的console output示例。

/etc/init/test.conf

Address

然后以root身份

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

消息存在于$ initctl start test initctl: Job failed to start 中,但控制台中没有该消息。

/var/log/syslog

如何将错误记录到控制台?

这是Ubuntu 14.04,

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

1 个答案:

答案 0 :(得分:3)

console output写入/dev/console,默认情况下是系统虚拟日志记录设备:它不会写入您的个人控制台(例如/dev/tty0)。

如果您尝试直接写入这些虚拟设备,则可以实际测试行为差异:

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

有关不同虚拟控制台设备之间差异的更多信息,请参阅this Unix StackExchange question

如果您真的想要,可以通过修改引导配置来更改/dev/console指向的内容:

# /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"

...但如果我是你,我只使用console log节而不是console output,然后拖尾生成的文件。