历经千辛万苦,终于有了自己的openstack开发环境,查看《allinone—openstack development environment》,就想新交了女朋友一样,是不是想要更进一步的了解她呢?
怀着激动的心情,就让我们一步一步的走进allinone的内心世界吧,在命令行敲入:
systemctl list-unit-files | grep openstack
systemctl的使用可以参考我的另外一篇博客《systemctl介绍》,上面的命令可以列出当前系统中所有已安装的服务。allinone环境会得到如下的输出:
# systemctl list-unit-files | grep openstack
openstack-ceilometer-alarm-evaluator.service enabled
openstack-ceilometer-alarm-notifier.service enabled
openstack-ceilometer-api.service enabled
openstack-ceilometer-central.service enabled
openstack-ceilometer-collector.service enabled
openstack-ceilometer-compute.service enabled
openstack-ceilometer-notification.service enabled
openstack-ceilometer-polling.service disabled
openstack-cinder-api.service enabled
openstack-cinder-backup.service enabled
openstack-cinder-scheduler.service enabled
openstack-cinder-volume.service enabled
openstack-glance-api.service enabled
openstack-glance-registry.service enabled
openstack-glance-scrubber.service disabled
openstack-keystone.service disabled
openstack-losetup.service enabled
openstack-nova-api.service enabled
openstack-nova-cert.service enabled
openstack-nova-compute.service enabled
openstack-nova-conductor.service enabled
openstack-nova-console.service disabled
openstack-nova-consoleauth.service enabled
openstack-nova-metadata-api.service disabled
openstack-nova-novncproxy.service enabled
openstack-nova-scheduler.service enabled
openstack-nova-xvpvncproxy.service disabled
openstack-swift-account-auditor.service enabled
openstack-swift-account-auditor@.service disabled
openstack-swift-account-reaper.service enabled
openstack-swift-account-reaper@.service disabled
openstack-swift-account-replicator.service enabled
openstack-swift-account-replicator@.service disabled
openstack-swift-account.service enabled
openstack-swift-account@.service disabled
openstack-swift-container-auditor.service enabled
openstack-swift-container-auditor@.service disabled
openstack-swift-container-reconciler.service disabled
openstack-swift-container-replicator.service enabled
openstack-swift-container-replicator@.service disabled
openstack-swift-container-updater.service enabled
openstack-swift-container-updater@.service disabled
openstack-swift-container.service enabled
openstack-swift-container@.service disabled
openstack-swift-object-auditor.service enabled
openstack-swift-object-auditor@.service disabled
openstack-swift-object-expirer.service enabled
openstack-swift-object-replicator.service enabled
openstack-swift-object-replicator@.service disabled
openstack-swift-object-updater.service enabled
openstack-swift-object-updater@.service disabled
openstack-swift-object.service enabled
openstack-swift-object@.service disabled
openstack-swift-proxy.service enabled
#
细心的读者应该会发现,图中总共包含了ceilometer、cinder、glance、keystone、nova、swift六个组件的单元,另外的neutron去哪儿了?让我们再找找,输入如下的命令:
systemctl list-unit-files | grep neutron
原来是这小子搞特殊化哦
# systemctl list-unit-files | grep neutron
neutron-dhcp-agent.service enabled
neutron-l3-agent.service enabled
neutron-metadata-agent.service enabled
neutron-netns-cleanup.service disabled
neutron-openvswitch-agent.service enabled
neutron-ovs-cleanup.service enabled
neutron-server.service enabled
#
所有可用的单元文件存放在 /usr/lib/systemd/system/ 和 /etc/systemd/system/ 目录(后者优先级更高),我们再来看看openstack各服务的文件,用户安装的服务一般放在/usr/lib/systemd/system/目录下,命令如下:
ls -lh /usr/lib/systemd/system/ | grep openstack
得到的结果如下:
# ls -lh /usr/lib/systemd/system/ | grep openstack
-rw-r--r--. 1 root root 274 Dec 22 06:38 openstack-ceilometer-alarm-evaluator.service
-rw-r--r--. 1 root root 274 Dec 22 06:38 openstack-ceilometer-alarm-notifier.service
-rw-r--r--. 1 root root 237 Dec 22 06:38 openstack-ceilometer-api.service
-rw-r--r--. 1 root root 276 Dec 22 06:38 openstack-ceilometer-central.service
-rw-r--r--. 1 root root 256 Dec 22 06:38 openstack-ceilometer-collector.service
-rw-r--r--. 1 root root 276 Dec 22 06:38 openstack-ceilometer-compute.service
-rw-r--r--. 1 root root 274 Dec 22 06:38 openstack-ceilometer-notification.service
-rw-r--r--. 1 root root 316 Dec 22 06:38 openstack-ceilometer-polling.service
-rw-r--r--. 1 root root 307 Dec 22 23:27 openstack-cinder-api.service
-rw-r--r--. 1 root root 316 Dec 22 23:27 openstack-cinder-backup.service
-rw-r--r--. 1 root root 325 Dec 22 23:27 openstack-cinder-scheduler.service
-rw-r--r--. 1 root root 316 Dec 22 23:27 openstack-cinder-volume.service
-rw-r--r--. 1 root root 261 Feb 5 15:26 openstack-glance-api.service
-rw-r--r--. 1 root root 271 Feb 5 15:26 openstack-glance-registry.service
-rw-r--r--. 1 root root 267 Feb 5 15:26 openstack-glance-scrubber.service
-rw-r--r--. 1 root root 242 Dec 22 02:52 openstack-keystone.service
-rw-r--r--. 1 root root 571 Mar 21 17:55 openstack-losetup.service
-rwxr-xr-x. 1 root root 230 Jan 25 19:28 openstack-nova-api.service
-rwxr-xr-x. 1 root root 232 Jan 25 19:28 openstack-nova-cert.service
-rwxr-xr-x. 1 root root 285 Jan 25 19:28 openstack-nova-compute.service
-rwxr-xr-x. 1 root root 242 Jan 25 19:28 openstack-nova-conductor.service
-rwxr-xr-x. 1 root root 251 Jan 25 19:28 openstack-nova-consoleauth.service
-rwxr-xr-x. 1 root root 244 Jan 25 19:28 openstack-nova-console.service
-rwxr-xr-x. 1 root root 248 Jan 25 19:28 openstack-nova-metadata-api.service
-rwxr-xr-x. 1 root root 285 Jan 25 19:28 openstack-nova-novncproxy.service
-rwxr-xr-x. 1 root root 242 Jan 25 19:28 openstack-nova-scheduler.service
-rwxr-xr-x. 1 root root 197 Jan 25 19:28 openstack-nova-xvpvncproxy.service
-rw-r--r--. 1 root root 286 Oct 1 05:29 openstack-swift-account-auditor.service
-rw-r--r--. 1 root root 264 Oct 1 05:29 openstack-swift-account-auditor@.service
-rw-r--r--. 1 root root 247 Oct 1 05:29 openstack-swift-account-reaper.service
-rw-r--r--. 1 root root 262 Oct 1 05:29 openstack-swift-account-reaper@.service
-rw-r--r--. 1 root root 322 Oct 1 05:29 openstack-swift-account-replicator.service
-rw-r--r--. 1 root root 270 Oct 1 05:29 openstack-swift-account-replicator@.service
-rw-r--r--. 1 root root 282 Oct 1 05:29 openstack-swift-account.service
-rw-r--r--. 1 root root 297 Oct 1 05:29 openstack-swift-account@.service
-rw-r--r--. 1 root root 255 Oct 1 05:29 openstack-swift-container-auditor.service
-rw-r--r--. 1 root root 270 Oct 1 05:29 openstack-swift-container-auditor@.service
-rw-r--r--. 1 root root 265 Oct 1 05:29 openstack-swift-container-reconciler.service
-rw-r--r--. 1 root root 328 Oct 1 05:29 openstack-swift-container-replicator.service
-rw-r--r--. 1 root root 276 Oct 1 05:29 openstack-swift-container-replicator@.service
-rw-r--r--. 1 root root 288 Oct 1 05:29 openstack-swift-container.service
-rw-r--r--. 1 root root 303 Oct 1 05:29 openstack-swift-container@.service
-rw-r--r--. 1 root root 255 Oct 1 05:29 openstack-swift-container-updater.service
-rw-r--r--. 1 root root 270 Oct 1 05:29 openstack-swift-container-updater@.service
-rw-r--r--. 1 root root 283 Oct 1 05:29 openstack-swift-object-auditor.service
-rw-r--r--. 1 root root 261 Oct 1 05:29 openstack-swift-object-auditor@.service
-rw-r--r--. 1 root root 247 Oct 1 05:29 openstack-swift-object-expirer.service
-rw-r--r--. 1 root root 319 Oct 1 05:29 openstack-swift-object-replicator.service
-rw-r--r--. 1 root root 267 Oct 1 05:29 openstack-swift-object-replicator@.service
-rw-r--r--. 1 root root 279 Oct 1 05:29 openstack-swift-object.service
-rw-r--r--. 1 root root 294 Oct 1 05:29 openstack-swift-object@.service
-rw-r--r--. 1 root root 246 Oct 1 05:29 openstack-swift-object-updater.service
-rw-r--r--. 1 root root 261 Oct 1 05:29 openstack-swift-object-updater@.service
-rw-r--r--. 1 root root 276 Oct 1 05:29 openstack-swift-proxy.service
#
查看neutron服务文件,ls -lh /usr/lib/systemd/system/ | grep neutron
,得到的结果:
# ls -lh /usr/lib/systemd/system/ | grep neutron
-rw-r--r--. 1 root root 497 Dec 22 03:25 neutron-dhcp-agent.service
-rw-r--r--. 1 root root 493 Dec 22 03:25 neutron-l3-agent.service
-rw-r--r--. 1 root root 517 Dec 22 03:25 neutron-metadata-agent.service
-rw-r--r--. 1 root root 987 Dec 22 03:25 neutron-netns-cleanup.service
-rw-r--r--. 1 root root 584 Dec 22 03:25 neutron-openvswitch-agent.service
-rw-r--r--. 1 root root 1011 Dec 22 03:25 neutron-ovs-cleanup.service
-rw-r--r--. 1 root root 532 Dec 22 03:25 neutron-server.service
#
找到了服务文件,就好比找到了女朋友心灵的某个入口,会打开一片新的天地,让你见识一个全新的世界,我们就来撕开这个领口,看一看这个全新的世界,以openstack-ceilometer-api.service
为例:
# cat /usr/lib/systemd/system/openstack-ceilometer-api.service
[Unit]
Description=OpenStack ceilometer API service
After=syslog.target network.target
[Service]
Type=simple
User=ceilometer
ExecStart=/usr/bin/ceilometer-api --logfile /var/log/ceilometer/api.log
[Install]
WantedBy=multi-user.target
#
重点看一下ExecStart=/usr/bin/ceilometer-api --logfile /var/log/ceilometer/api.log
发现跟
# ps -ef | grep ceilometer-api
ceilome+ 1168 1 3 Mar24 ? 00:14:48 /usr/bin/python2 /usr/bin/ceilometer-api --logfile /var/log/ceilometer/api.log
的输出结果一致,这就是ceilometer-api的启动命令,启动脚本为/usr/bin/ceilometer-api
如果你是一个好奇心很强的程序员,想要刨根究底,那么这就是ceilometer-api的入口了,快去看看里面都写了些什么吧,我的代码是Liberty版本的5.0.2Tag,跟master分支上的代码有较大的差别,后需要将按照master分支上的代码进行整理,我的ceilometer-api启动脚本内容为:
#!/usr/bin/python2
# PBR Generated from u'console_scripts'
import sys
from ceilometer.cmd.api import main
if __name__ == "__main__":
sys.exit(main())
你已经从操作系统上正确的找到一个openstack组件服务的入口了,接下来就可以对接上你熟悉的代码了,加油!