新贵控制台输出不起作用

Upstart console output not working

我使用了 Upstart 为 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

然后作为 root

$ initctl start test
initctl: Job failed to start

消息出现在 /var/log/syslog 中,但消息不出现在控制台中。

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

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

这是Ubuntu14.04,

$ initctl version
init (upstart 1.12.1)

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 然后尾随生成的文件。