Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for supervisord #588

Merged
merged 3 commits into from
Apr 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 45 additions & 2 deletions build-scripts/ubuntu-1604/postinst_node
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ After=network.target
[Service]
Type=simple
EnvironmentFile=$GENERAL_CONFIG_DIR/node_control.conf
ExecStart=/usr/bin/env python3 -O /usr/local/bin/start_node_control_tool \$TEST_MODE --hold-ext \$HOLD_EXT
ExecStart=/usr/bin/env python3 -O /usr/local/bin/start_node_control_tool \${TEST_MODE} --hold-ext "\${HOLD_EXT}"
Restart=on-failure
RestartSec=10
StartLimitBurst=10
Expand All @@ -120,14 +120,57 @@ TimeoutSec=300
WantedBy=multi-user.target
EOF

# add supervisord script
cat <<EOF > /etc/supervisor/indy-node.conf
[supervisord]
nodaemon=true
logfile=/var/log/indy/supervisord.log
logfile_maxbytes=10MB
loglevel=critical

[supervisorctl]
serverurl=http://127.0.0.1:9001

[inet_http_server]
port = 127.0.0.1:9001

[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface

[program:indy-node]
command=sh -ac '. $GENERAL_CONFIG_DIR/indy.env;/usr/bin/env python3 -O /usr/local/bin/start_indy_node \${NODE_NAME} \${NODE_PORT} \${NODE_CLIENT_PORT}'
user=indy
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0
autorestart=true
startsecs=15
startretries=6
stopasgroup=true
killasgroup=true

[program:indy-node-control]
command=sh -ac '. $GENERAL_CONFIG_DIR/node_control.conf;/usr/bin/env python3 -O /usr/local/bin/start_node_control_tool \${TEST_MODE} --hold-ext "\${HOLD_EXT}"'
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0
autorestart=true
startsecs=15
startretries=6
stopasgroup=true
killasgroup=true
EOF

HOLD_EXT_ADDED=$(grep HOLD_EXT /etc/indy/node_control.conf)
if [ ! -f $GENERAL_CONFIG_DIR/node_control.conf ] || [ -z "${HOLD_EXT_ADDED}" ]; then
cat <<EOF > $GENERAL_CONFIG_DIR/node_control.conf
# Uncomment this to run agent in test mode:
#TEST_MODE=--test

TEST_MODE=
HOLD_EXT=\"\"
HOLD_EXT=
EOF
fi

Expand Down
35 changes: 28 additions & 7 deletions scripts/restart_indy_node_ubuntu1604.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,32 @@
#!/bin/bash -x

# Upgrade may change service files
systemctl daemon-reload
systemctl reset-failed
if [ "$INDY_CONTROL" = "" ]; then

echo "Starting indy-node"
systemctl start indy-node
# Upgrade may change service files
systemctl daemon-reload
systemctl reset-failed

echo "Restarting agent"
systemctl restart indy-node-control
echo "Starting indy-node"
systemctl start indy-node

echo "Restarting agent"
systemctl restart indy-node-control

elif [ "$INDY_CONTROL" = "supervisorctl" ]; then

# Upgrade may change service files
supervisorctl reread
supervisorctl update

echo "Starting indy-node"
supervisorctl start indy-node

echo "Restarting agent"
supervisorctl restart indy-node-control

else

echo "Invalid setting for 'INDY_CONTROL' environment variable: $INDY_CONTROL"
exit 1

fi
19 changes: 17 additions & 2 deletions scripts/upgrade_indy_node_ubuntu1604.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,23 @@ if [ $ret -ne 0 ] ; then
exit 1
fi

echo "Stop indy-node"
systemctl stop indy-node
if [ "$INDY_CONTROL" = "" ]; then

echo "Stop indy-node"
systemctl stop indy-node

elif [ "$INDY_CONTROL" = "supervisorctl" ]; then

echo "Stop indy-node"
supervisorctl stop indy-node

else

echo "Invalid setting for 'INDY_CONTROL' environment variable: $INDY_CONTROL"
exit 1

fi


echo "Run indy upgrade to $deps"
apt-get -y --allow-downgrades --allow-change-held-packages --reinstall install $deps
Expand Down
19 changes: 17 additions & 2 deletions scripts/upgrade_indy_node_ubuntu1604_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,23 @@ if [ $ret -ne 0 ] ; then
exit 1
fi

echo "Stop indy-node"
systemctl stop indy-node
if [ "$INDY_CONTROL" = "" ]; then

echo "Stop indy-node"
systemctl stop indy-node

elif [ "$INDY_CONTROL" = "supervisorctl" ]; then

echo "Stop indy-node"
supervisorctl stop indy-node

else

echo "Invalid setting for 'INDY_CONTROL' environment variable: $INDY_CONTROL"
exit 1

fi


echo "Run indy upgrade to $deps"
apt-get -y --allow-downgrades --allow-change-held-packages --reinstall install $deps
Expand Down
56 changes: 56 additions & 0 deletions scripts/validator-info
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,16 @@ class ValidatorStats(BaseStats):

@staticmethod
def get_process_state():
ctl = os.getenv('INDY_CONTROL', 'systemctl')
if ctl == "systemctl":
return ValidatorStats.get_process_state_via_systemctl()
elif ctl == "supervisorctl":
return ValidatorStats.get_process_state_via_supervisorctl()
else:
return "Invalid value for INDY_CONTROL environment variable: '%s'" % ctl

@staticmethod
def get_process_state_via_systemctl():
ret = subprocess.check_output(
'systemctl is-failed indy-node; exit 0',
stderr=subprocess.STDOUT, shell=True
Expand All @@ -367,8 +377,36 @@ class ValidatorStats(BaseStats):
)
return None

@staticmethod
def get_process_state_via_supervisorctl():
ret = subprocess.check_output(
"supervisorctl status indy-node | awk '{print $2}'; exit 0",
stderr=subprocess.STDOUT, shell=True
)
ret = ret.decode().strip()
if ret == 'STOPPED':
return 'stopped'
elif ret == 'RUNNING':
return 'running'
else:
logger.info(
"Non-expected output for indy-node "
"status: {}".format(ret)
)
return None

@staticmethod
def get_enabled_state():
ctl = os.getenv('INDY_CONTROL', 'systemctl')
if ctl == "systemctl":
return ValidatorStats.get_enabled_state_via_systemctl()
elif ctl == "supervisorctl":
return ValidatorStats.get_enabled_state_via_supervisorctl()
else:
return "Invalid value for INDY_CONTROL environment variable: '%s'" % ctl

@staticmethod
def get_enabled_state_via_systemctl():
ret = subprocess.check_output(
'systemctl is-enabled indy-node; exit 0',
stderr=subprocess.STDOUT, shell=True
Expand All @@ -385,6 +423,24 @@ class ValidatorStats(BaseStats):
)
return None

@staticmethod
def get_enabled_state_via_supervisorctl():
ret = subprocess.check_output(
"supervisorctl status indy-node | awk '{print $2}'; exit 0",
stderr=subprocess.STDOUT, shell=True
)
ret = ret.decode().strip()
if ret in ('RUNNING', 'BACKOFF', 'STARTING'):
return True
elif ret == 'STOPPED':
return False
else:
logger.info(
"Non-expected output for indy-node "
"is-enabled state: {}".format(ret)
)
return None

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
# TODO move that to classes too
Expand Down