Skip to content

Commit e219ad2

Browse files
committed
moar
1 parent 54db01d commit e219ad2

2 files changed

Lines changed: 19 additions & 2 deletions

File tree

install.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
1+
# Note, this contains some advanced info.
2+
13
import os
24
import sys
35
import subprocess
46

7+
# Import Cloudify's context object.
8+
# This provides several useful functions as well as allowing to pass
9+
# contextual information of an application.
510
from cloudify import ctx
611

712

813
IS_WIN = os.name == 'nt'
9-
# is this needed?
1014
IS_DARWIN = (sys.platform == 'darwin')
15+
16+
# Get the port from the blueprint. We're running in the context of the
17+
# `http_web_server` node so we can read its `port` property.
1118
PORT = ctx.node.properties['port']
1219

1320

@@ -16,11 +23,15 @@ def run_server():
1623
if not IS_WIN:
1724
webserver_cmd.insert(0, 'nohup')
1825

26+
# The ctx object provides a built in logger.
1927
ctx.logger.info('Running WebServer locally on port: {0}'.format(PORT))
28+
# emulating /dev/null
2029
dn = open(os.devnull, 'wb')
2130
process = subprocess.Popen(webserver_cmd, stdout=dn, stderr=dn)
2231

23-
if not IS_WIN:
32+
# we need this for linux because on linux process.pid is not accurate.
33+
# it provides somewhat arbitrary values.
34+
if not IS_WIN and not IS_DARWIN:
2435
del webserver_cmd[0]
2536
get_pid = ['pidof', '-s']
2637
get_pid.extend(webserver_cmd)
@@ -31,6 +42,10 @@ def run_server():
3142

3243
def set_pid(pid):
3344
ctx.logger.info('Setting `pid` runtime property: {0}'.format(pid))
45+
# We can set runtime information in our context object which
46+
# can later be read somewhere in the context of the instance.
47+
# For instance, we want to save the `pid` here so that when we
48+
# run `uninstall.py`, we can destroy the process.
3449
ctx.instance.runtime_properties['pid'] = pid
3550

3651

uninstall.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
from cloudify import ctx
55

6+
# Here, we read the `pid` runtime property which we previously
7+
# saved when running `install.py`
68
pid = ctx.instance.runtime_properties['pid']
79
ctx.logger.info('Running process PID: {0}'.format(pid))
810
try:

0 commit comments

Comments
 (0)