Goi*_*Off 5 linux centos init-script upstart
我目前正在从 CentOS 5.5 迁移到 6.4。将/etc/inittab 的内容转换为新贵很有趣。遇到了很多小问题,但现在我已经掌握了。我找到的最好的文档是针对 Ubuntu 的:
http://upstart.ubuntu.com/cookbook/#id416
它对我遇到的各种新贵问题很有帮助。唯一的问题是某些 ubuntu 项目不适用于 CentOS(无法使记录器功能正常工作,但找到了解决方法“exec >/dev/kmsg 2>&1”)。
是否有任何 CentOS 特定文档可以帮助处理新贵脚本?CentOS 需要与 Ubuntu 相同的文档..Argg!!
由于我是新贵的新手,我仍然不确定最佳实践是什么。下面的脚本似乎也很好用。欢迎对此发表任何评论..谢谢!!
这是一个启动 TTY 的脚本,用于向服务器提供调制解调器拨号服务。它可以为通过 USB、串行、网络调制解调器组(数字端口服务器)连接的调制解调器启动 TTY。它使用由管理员维护的文件来指定要启动的 tty:
/etc/init/ssi-ttys.conf:
start on stopped rc RUNLEVEL=[2345]
task
script
#--------------------------------------------------------------------
# The following exec will send the data to the kernels ring buffer.
# Once the syslog daemon starts, this data will be redirected to the
# system log file. So, the echo below will be written out to
# /var/log/messages. Helps out a ton when you need to debug these
# scripts.
#--------------------------------------------------------------------
exec >/dev/kmsg 2>&1
re="^#"
while read line
do
tty=
identifier=
# Proccess /etc/ssi-init-ttys.conf lines without comments
if [[ ! $line =~ $re ]]
then
set $line
tty=$1
identifier=$2
echo "Starting TTY ($tty) ($identifier) using ssi-tty.conf"
#-----------------------------------------------------------------
# Remember that Upstart runs every script section using /bin/sh -e.
# This means that if any simple command fails, the shell will exit.
# So, this is why || true is added to the start so if one of the
# TTYs is already running (Which would normally cause an exit,
# the loop will continue and start other TTYs without exiting.
# Add || true to any system command that might return a code other
# than 0.
#------------------------------------------------------------------
initctl start ssi-tty TTY=$tty IDENTIFIER=$identifier || true
fi
done </etc/ssi-init-ttys.conf
end script
Run Code Online (Sandbox Code Playgroud)
/etc/init/ssi-tty.conf:
stop on runlevel [S016]
respawn
respawn limit 5 10
# There's an automatic limit set to this: if a process is respawned more
# than 5 times within 10 seconds, it will be stopped and not restarted.
# Check /var/log/messages and /var/log/mgetty.log.<tty> for error messages
instance $TTY
script
# Regex for serial and USB ttys
reg1="ttyUSB"
reg2="ttyS"
m_flg=""
# Check for USB or serial ttys which use the -D flag for mgetty
if [[ $TTY =~ $reg1 ]] || [[ $TTY =~ $reg2 ]]
then
# Use -D flag with mgetty for ttyUSB and ttyS ports
m_flg="-D"
fi
exec /sbin/mgetty $m_flg $TTY $IDENTIFIER
end script
usage 'ssi-tty TTY=ttyX IDENTIFIER=Z - ttyX is the tty id and Z is the /etc/gettydefs identifier'
Run Code Online (Sandbox Code Playgroud)
/etc/ssi-init-ttys.conf:
# Serial port TTY
ttyS0 9
# USB port tty
ttyUSB0 9
# Digi port tty
ttyA18 9
Run Code Online (Sandbox Code Playgroud)
注意: 9 表示用于 tty 的适当的 /etc/gettydefs 标识符。
不要担心upstart,RHEL(以及 CentOS)正在迁移到systemd第 7 版。即使是 Ubuntu 也决定摆脱 upstart(请参阅Mark Shuttleworth 的这篇博客文章)。