openstack(liberty): devstack之screen
在devstack的stack.sh文件中,可以看到所有配置的service启动方式有两种,根据是否USE_SCREEN进行是在screen window中启动,还是直接起。
默认情况,USE_SCREEN是true的,这个可以在devstack/stackrc中找到,这个文件默认将USE_SCREEN设置为True。 即,所有的service将在screen window中启动。即每一个service对应一个screen window。下面,我就拿nova api这个service的启动代码进行分析这个是如何在SCREEN窗口中启动的。
1. 下面的代码在devstack/lib/nova中。红色部分就是启动的第一级函数调用。
# start_nova_api() - Start the API process ahead of other things
function start_nova_api {
# Get right service port for testing
local service_port=$NOVA_SERVICE_PORT
local service_protocol=$NOVA_SERVICE_PROTOCOL
if is_service_enabled tls-proxy; then
service_port=$NOVA_SERVICE_PORT_INT
service_protocol="http"
fi # Hack to set the path for rootwrap
local old_path=$PATH
export PATH=$NOVA_BIN_DIR:$PATH # If the site is not enabled then we are in a grenade scenario
local enabled_site_file=$(apache_site_config_for nova-api)
if [ -f ${enabled_site_file} ] && [ "$NOVA_USE_MOD_WSGI" == "True" ]; then
enable_apache_site nova-api
enable_apache_site nova-ec2-api
restart_apache_server
tail_log nova-api /var/log/$APACHE_NAME/nova-api.log
tail_log nova-ec2-api /var/log/$APACHE_NAME/nova-ec2-api.log
else
run_process n-api "$NOVA_BIN_DIR/nova-api"
fi echo "Waiting for nova-api to start..."
if ! wait_for_service $SERVICE_TIMEOUT $service_protocol://$SERVICE_HOST:$service_port; then
die $LINENO "nova-api did not start"
fi # Start proxies if enabled
if is_service_enabled tls-proxy; then
start_tls_proxy '*' $NOVA_SERVICE_PORT $NOVA_SERVICE_HOST $NOVA_SERVICE_PORT_INT &
start_tls_proxy '*' $EC2_SERVICE_PORT $NOVA_SERVICE_HOST $EC2_SERVICE_PORT_INT &
fi export PATH=$old_path
}
2. run_process函数,devstack/functions-common.
# Run a single service under screen or directly
# If the command includes shell metachatacters (;<>*) it must be run using a shell
# If an optional group is provided sg will be used to run the
# command as that group.
# run_process service "command-line" [group]
function run_process {
local service=$1 #此处的service就是n-api
local command="$2" #此处的command就是/usr/bin/nova-api,其他的nova相关的指令都在/usr/bin目录下。
local group=$ if is_service_enabled $service; then
if [[ "$USE_SCREEN" = "True" ]]; then #由于前面分析了USE_SCREEN的值为True,所以,进入到screen_process处理
screen_process "$service" "$command" "$group"
else
# Spawn directly without screen
_run_process "$service" "$command" "$group" &
fi
fi
}
3. screen_process函数,在devstack/functions-common文件中
# Helper to launch a process in a named screen
# Uses globals ``CURRENT_LOG_TIME``, ```LOGDIR``, ``SCREEN_LOGDIR``, `SCREEN_NAME``,
# ``SERVICE_DIR``, ``USE_SCREEN``
# screen_process name "command-line" [group]
# Run a command in a shell in a screen window, if an optional group
# is provided, use sg to set the group of the command.
function screen_process {
local name=$1 #要启动的service的名字,此处为n-api
local command="$2" #要执行的命令,此处为nova-api
local group=$ SCREEN_NAME=${SCREEN_NAME:-stack}
SERVICE_DIR=${SERVICE_DIR:-${DEST}/status}
USE_SCREEN=$(trueorfalse True USE_SCREEN) screen -S $SCREEN_NAME -X screen -t $name #启动一个名为stack的session,在这个session中执行screen命令(给当前screen窗口起名为n-api)
local real_logfile="${LOGDIR}/${name}.log.${CURRENT_LOG_TIME}"
echo "LOGDIR: $LOGDIR"
echo "SCREEN_LOGDIR: $SCREEN_LOGDIR"
echo "log: $real_logfile"
if [[ -n ${LOGDIR} ]]; then
screen -S $SCREEN_NAME -p $name -X logfile "$real_logfile"
screen -S $SCREEN_NAME -p $name -X log on
ln -sf "$real_logfile" ${LOGDIR}/${name}.log
if [[ -n ${SCREEN_LOGDIR} ]]; then
# Drop the backward-compat symlink
ln -sf "$real_logfile" ${SCREEN_LOGDIR}/screen-${}.log
fi
fi # sleep to allow bash to be ready to be send the command - we are
# creating a new window in screen and then sends characters, so if
# bash isn't running by the time we send the command, nothing
# happens. This sleep was added originally to handle gate runs
# where we needed this to be at least seconds to pass
# consistently on slow clouds. Now this is configurable so that we
# can determine a reasonable value for the local case which should
# be much smaller.
sleep ${SCREEN_SLEEP:-} NL=`echo -ne '\015'`
# This fun command does the following:
# - the passed server command is backgrounded
# - the pid of the background process is saved in the usual place
# - the server process is brought back to the foreground
# - if the server process exits prematurely the fg command errors
# and a message is written to stdout and the process failure file
#
# The pid saved can be used in stop_process() as a process group
# id to kill off all child processes
if [[ -n "$group" ]]; then
command="sg $group '$command'"
fi # Append the process to the screen rc file
screen_rc "$name" "$command" screen -S $SCREEN_NAME -p $name -X stuff "$command & echo \$! >$SERVICE_DIR/$SCREEN_NAME/${name}.pid; fg || echo \"$name failed to start\" | tee \"$SERVICE_DIR/$SCREEN_NAME/${name}.failure\"$NL" #在指定name为nova-api的screen窗口里面执行启动nova-api的服务,并将pid写入对应文件。如果出错,将错误信息tee到指定格式的文件
}
其中,上面标识红色的部分,是关键指令。通过上面的3个函数的分析,是不是对于devstack的各个service的启动比较熟悉了?或者说有个比较直观感性的认识了?
下面,介绍一下,screen相关的操作。首先看看screen都有些什么命令选项,或者说screen的帮助信息:
[root@CloudGame shelltest]# screen -help
Use: screen [-opts] [cmd [args]]
or: screen -r [host.tty] Options:
- Use IPv4.
- Use IPv6.
-a Force all capabilities into each window's termcap.
-A -[r|R] Adapt all windows to the new display width & height.
-c file Read configuration file instead of '.screenrc'.
-d (-r) Detach the elsewhere running screen (and reattach here).
-dmS name Start as daemon: Screen session in detached mode.
-D (-r) Detach and logout remote (and reattach here).
-D -RR Do whatever is needed to get a screen session.
-e xy Change command characters.
-f Flow control on, -fn = off, -fa = auto.
-h lines Set the size of the scrollback history buffer.
-i Interrupt output sooner when flow control is on.
-l Login mode on (update /var/run/utmp), -ln = off.
-list or -ls. Do nothing, just list our SockDir.
-L Turn on output logging.
-m ignore $STY variable, do create a new screen session.
-O Choose optimal output rather than exact vt100 emulation.
-p window Preselect the named window if it exists.
-q Quiet startup. Exits with non-zero return code if unsuccessful.
-r Reattach to a detached screen process.
-R Reattach if possible, otherwise start a new session.
-s shell Shell to execute rather than $SHELL.
-S sockname Name this session <pid>.sockname instead of <pid>.<tty>.<host>.
-t title Set title. (window's name).
-T term Use term as $TERM for windows, rather than "screen".
-U Tell screen to use UTF- encoding.
-v Print "Screen version 4.00.03 (FAU) 23-Oct-06".
-wipe Do nothing, just clean up SockDir.
-x Attach to a not detached screen. (Multi display mode).
-X Execute <cmd> as a screen command in the specified session.
在devstack环境下,相关的操作指令主要有:
screen -ls: 列出当前sockdir。
[stack@ip---- devstack]$ screen -ls
There is a screen on:
.stack (Detached)
Socket in /var/run/screen/S-stack.
attach screen:
[stack@ip---- devstack]$ screen -r .stack
进入了screen后,通过执行ctrl+a + n或者p键,可以实现screen窗口的滚动切换。当前的服务窗口对应于服务名字上有个*号:
。。。。。。。。。。。。。。。
--03T00::00Z", "name": "CloudpipeUpdate", "links": [], "namespace": "http://docs.openstack.org/compute/ext/fake_xml", "alias": "os-cloudpipe-update", "description": ""}, {"updated": "2014-12-03T00:00:00Z", "name": "ConfigDrive", "links": [], "namespace": "http://docs.openstack.org/compute/ext/fake_xml", "alias": "os-config-drive", "description": "Config Drive Extension."}, {"updated": "2014-12-03T00:00:00Z", "name": "ConsoleAuthTokens", "links": [], "namespace": "http://docs.openstack.org/compute/ext/fake_xml", "alias": "os-console-auth-tokens", "description": "Console token authentication support."}, {"updated": "2014-12-03T00:00:00Z", "name": "ConsoleOutput", "links": [], "namespace": "http://docs.openstack.org/compute/ext/fake_xml", "alias": "os-console-output", "description": "Console log output support, with tailing ability."}, {"updated": "2014-12-03T00:00:00Z", "name": "Consoles", "links": [], "namespace": "http://docs.openstack.org/compute/ext/fake_xml", "alias": "os-consoles", "description": "Interactive Console support."}, {"updated": "2014-12-03T00:00:00Z", "name": "CreateBackup", "links": [], "namespace": "http://docs.openstack.org/compute/ext/fake_xml", "alias": "os-create-backup", "description": "Create a backup of a server."}, {"updated": "2014-12-03T00:00:00Z", "name": "Createserverext", "links": [], "namespace": "http://docs.openstack.org/compute/ext/fake_xml", "alias": "os-create-server-ext", "description": ""}, {"updated": "2014-12-03T00:00:00Z", "name": "DeferredDelete", "links": [], "namespace": "http://docs.openstack.org/compute/ext/fake_xml", "alias": "os-deferred-delete", "description": "Instance deferred delete."}, {"updated": "2014-12-03T00:00:0
-- ::05.346975
:q! -$ stack@ip---- $(L) dstat $(L) key $(L) key-access 4$(L) horizon* (ip----/0.29 0.30 0.74)
在当前窗口执行ctrl+c就是杀掉当前的process。
deatch screen(ctrl+a + d):
注意,是ctrl+a指令输入后等一会,再输入d键。
进入服务列表模式(ctrl+a+双引号键,双引号键shift+,就是Enter键左边那个):
在这种模式下,当前所在的process对应的服务名字高亮显示,例如上图中的horizon,此时,点击enter,会进入到常规模式。
其他一些相关的指令,自己以后慢慢摸索吧!
openstack(liberty): devstack之screen的更多相关文章
- openstack(liberty): devstack中的iniset/iniget函数分析
这个ini开头的函数在devstack的启动配置中用的非常多,他主要负责.ini文件的配置,这个过程包括对相关ini文件的添加,注释,删除,获取信息,多行信息获取等. 这里主要说的iniset和ini ...
- [OpenStack] [Liberty] Neutron单网卡桥接模式访问外网
环境配置: * Exsi一台 * Exsi创建的单网卡虚拟机一台 * Ubuntu 14LTS 64位操作系统 * OpenStack Liberty版本 * 使用Neutron网络而非Nova网络 ...
- [译] OpenStack Liberty 版本中的53个新变化
一个新的秋季,一个新的OpenStack 版本.OpenStack 的第12个版本,Liberty,在10月15日如期交付,而且目前发行版本已经备好了.那么我们期望能从过去六个月时间的开发中获得些什么 ...
- CentOS7.4安装部署openstack [Liberty版] (二)
继上一篇博客CentOS7.4安装部署openstack [Liberty版] (一),本篇继续讲述后续部分的内容 一.添加块设备存储服务 1.服务简述: OpenStack块存储服务为实例提供块存储 ...
- CentOS7.4安装部署openstack [Liberty版] (一)
一.OpenStack简介 OpenStack是一个由NASA(美国国家航空航天局)和Rackspace合作研发并发起的,以Apache许可证授权的自由软件和开放源代码项目. OpenStack是一个 ...
- openstack(liberty):部署实验平台(一,基础网络环境搭建)
openstack项目的研究,到今天,算是要进入真实环境了,要部署实验平台了.不再用devstack了.也就是说,要独立controller,compute,storage和network了.要做这个 ...
- openstack(liberty):部署实验平台(三,简单版本软件安装 之cinder,swift)
今天这里追加存储相关的部署,主要是Block和Object,为了看到效果,简单的部署在单节点上,即Block一个节点,Object对应一个节点. 读者可能会觉得我这个图和之前的两个post有点点不同, ...
- openstack(liberty): 简单网络连接图
openstack起初的网络部分是和计算核心nova合在一起的,后来被拆分出来,独立成为一个模块, 现在名为Neutron. 本博文是学习记录,记录的是基于GRE tunnel技术的neutron和计 ...
- [Openstack]使用devstack自己主动化安装
os环境为: ubuntu14.04 安装步骤: 更新系统软件包: sudo apt-get dist-upgrade #出现无法訪问到ubuntu官网的错误. 安装git: sudo apt-get ...
随机推荐
- magento问题集3
MISSING LANGUAGE FILES OR DIRECTORIES A:已经装了俄语包,也是russian目录,在前台也可以用.但是在后台最上面总是显示MISSING LANGUAGE FIL ...
- Magento后台订单显示产品图片的修改方法
Magento后台订单原来是没有显示产品图片,客服业务还得到网站前台查找这个产品的图片提供给发货部,这样是很不方便的.为提高工作效率,应客服业务要求,现对Magento后台订单进行修改,使订单页面就显 ...
- Redis 设计与实现读书笔记一 Redis字符串
1 Redis 是C语言实现的 2 C字符串是 /0 结束的字符数组 3 Redis具体的动态字符串实现 /* * 保存字符串对象的结构 */ struct sdshdr { // buf 中已占用空 ...
- 动态数组 - ArrayList
前言 如果数组的大小要随时间变化,那么数组操作起来就比较麻烦. 在C++中,这种情况要用到动态向量Vector. 而Java中,提供了一种叫做ArrayList的泛型数组结构类型,提供相似的作用. 其 ...
- python numpy 模块简单介绍
用python自带的list去处理数组效率很低, numpy就诞生了, 它提供了ndarry对象,N-dimensional object, 是存储单一数据类型的多维数组,即所有的元素都是同一种类型. ...
- MyEclipse+Struts+Hibernate+Mysql开发环境配置
软件: jdk-6u22-windows-x64.exe apache-tomcat-6.0.29.exe mysql-5.1.51-winx64.exe myeclipse-8.6.0-win32. ...
- leetcode 124. Binary Tree Maximum Path Sum ----- java
Given a binary tree, find the maximum path sum. For this problem, a path is defined as any sequence ...
- POJ1149 PIGS (网络流)
PIGS Time Limit: 1000MS M ...
- nginx和apache下的url rewrite
将服务器上面的数据同步到本地之后,发现打开首页显示不正常,本地服务器是apache,经过打开url rewrite之后本地首页正常显示. 原因是phpwind本身支持了url rewrite的功能,但 ...
- Linux驱动设计——阻塞和同步
阻塞和非阻塞是设备访问的两种基本方式,阻塞和非阻塞驱动程序使用时,经常会用到等待队列. 阻塞和非阻塞 阻塞操作是指在执行设备操作时,若不能获得资源,则挂起进程直到满足可操作的条件后再进行操作.被挂起的 ...