Pau*_*per 6 console logging upstart
我使用Upstart提供的控制台输出示例.
/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
Run Code Online (Sandbox Code Playgroud)
然后作为根
$ initctl start test
initctl: Job failed to start
Run Code Online (Sandbox Code Playgroud)
消息存在/var/log/syslog,但控制台中不存在该消息.
Jul 23 07:42:19 paul test[26595]: ERROR: foo!
Run Code Online (Sandbox Code Playgroud)
如何将错误记录到控制台?
这是Ubuntu 14.04,
$ initctl version
init (upstart 1.12.1)
Run Code Online (Sandbox Code Playgroud)
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
Run Code Online (Sandbox Code Playgroud)
有关不同虚拟控制台设备之间差异的更多信息,请参阅此 Unix StackExchange 问题。
如果您确实愿意,可以/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"
Run Code Online (Sandbox Code Playgroud)
...但如果我是你,我只会使用该console log节而不是console output然后尾部生成的文件。
| 归档时间: |
|
| 查看次数: |
1202 次 |
| 最近记录: |