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 ...
随机推荐
- C# <%@ Register %>指令
将别名与命名空间及类名关联起来,以便在自定义服务器控件语法中使用简明的表示法. <%@ register tagprefix="tagprefix" namespace=&q ...
- Runtime 、 Block
1 使用Block方式,对学生对象进行排序. 1.1 问题 在iOS4.0+ 和Mac OS X 10.6+ 中添加了Block概念,以对C语言进行扩展.在Block中可以定义参数列表.返回类型,还可 ...
- D - 排列
#include<cstdio> #include<algorithm> #include<string.h> using namespace std; #defi ...
- flexbox的术语
在详细阅读这篇文章之前,我们很有必要先了解flexbox的几个常用术语,这样有助于大家对后文的理解. 伸缩容器:一个设有“display:flex”或“display:inline-flex”的元素 ...
- 225. Implement Stack using Queues
代码如下: class MyStack { // Push element x onto stack. Queue<Integer> queue=new ArrayDeque<> ...
- 应用上下文配置【AppConfig】
从spring3.0开始,Spring将JavaConfig整合到核心模块,普通的POJO只需要标注@Configuration注解,就可以成为spring配置类,并通过在方法上标注@Bean注解的方 ...
- 1-1 Java简介
主要内容: <1>Java平台应用 <2>核心概念:JVM.JDK.JRE <3>搭建Java开发环境 <4>使用工具开发Java程序 <5> ...
- HTML文件结构
转载(http://jingyan.baidu.com/article/75ab0bcbf04a75d6864db2fd.html) HTML文件结构 HTML文件均以<html>标记开始 ...
- linux下的符号链接和硬链接
一 Linux下链接文件的作用 Linux特别注重用户的权限,而链接文件的作用也正体现了这个方面.对源文件的位置进行了隐藏,用户只对链接文件操作. 二 链接文件的区别 链接文件分为硬链接文件和软 ...
- 硬链接与软连接[转自vbird]
前言 在 Linux 底下的连结档有两种,一种是类似 Windows 的快捷方式功能的文件,可以让你快速的链接到目标文件(或目录),这种是软链接: 另一种则是透过文件系统的 inode 连结来产生新档 ...