Commit 948ce5f2 authored by Rafael Monnerat's avatar Rafael Monnerat

Add slapos node boot replacement for slapos-start

  This new command aims to be used on linux start up. It wait until
  network is up (ipv4 and ipv6), them it runs slapos node format and bang.

  It removes the .timestamp on all partitions, in order to force re-run.
parent edf2e60a
......@@ -101,6 +101,7 @@ setup(name=name,
'node report = slapos.cli.slapgrid:ReportCommand',
'node software = slapos.cli.slapgrid:SoftwareCommand',
'node instance = slapos.cli.slapgrid:InstanceCommand',
'node boot = slapos.cli.boot:BootCommand',
# SlapOS client commands
'console = slapos.cli.console:ConsoleCommand',
'configure local = slapos.cli.configure_local:ConfigureLocalCommand',
......
# -*- coding: utf-8 -*-
import subprocess
from time import sleep
import socket
import glob
import os
from slapos.cli.command import must_be_root
from slapos.cli.entry import SlapOSApp
from slapos.cli.config import ConfigCommand
def _removeTimestamp(instancehome):
"""
Remove .timestamp from all partitions
"""
timestamp_glob_path = "%s/slappart*/.timestamp" % instancehome
Please register or sign in to reply
for timestamp_path in glob.glob(timestamp_glob_path):
print "Removing %s" % timestamp_path
os.remove(timestamp_path)
def _runBang(app):
"""
Launch slapos node format.
"""
print "[BOOT] Invoking slapos node bang..."
result = app.run(['node', 'bang', '-m', 'Reboot'])
if result == 1:
return 0
return 1
def _runFormat(app):
"""
Launch slapos node format.
"""
print "[BOOT] Invoking slapos node format..."
result = app.run(['node', 'format', '--now', '--verbose'])
if result == 1:
return 0
return 1
def _ping():
"""
Ping a hostname
"""
print "[BOOT] Invoking ping to ipv4 network..."
p = subprocess.Popen(
["ping", "-c", "2", "www.google.com"],
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout, stderr = p.communicate()
if p.returncode == 0:
print "[BOOT] IPv4 network reachable..."
return 1
print "[BOOT] [ERROR] IPv4 network unreachable..."
return 0
def _ping6():
"""
Ping an ipv6 address
"""
print "[BOOT] Invoking ping to ipv6 network..."
p = subprocess.Popen(
["ping6", "-c", "2", "ipv6.google.com"],
  • Hi. ping6 to ipv6.google.com is not a good idea, because by default re6st does not provide access to ipv6 internet. Re6st node can access to other re6st nodes only and ipv6.google.com is not a member of our re6st network. Do we have any appropriate hosts in our re6st network? So far, when I invoke slapos node boot, I edit /etc/hosts and add a fake ipv6.google.com to make that command work.

  • @rafael Hi Rafael, do you have any ideas?

Please register or sign in to reply
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout, stderr = p.communicate()
if p.returncode == 0:
print "[BOOT] IPv6 network reachable..."
return 1
print "[BOOT] [ERROR] IPv4 network unreachable..."
return 0
class BootCommand(ConfigCommand):
"""
Test network and invoke simple format and bang (Use on Linux startup)
"""
command_group = 'node'
def get_parser(self, prog_name):
ap = super(BootCommand, self).get_parser(prog_name)
ap.add_argument('-m', '--message',
default="Reboot",
help='Message for bang')
return ap
@must_be_root
def take_action(self, args):
configp = self.fetch_config(args)
# Make sure ipv4 is working
instance_root = configp.get('slapos','instance_root')
is_ready = _ping()
while is_ready == 0:
sleep(5)
is_ready = _ping()
# Make sure ipv6 is working
is_ready = _ping6()
while is_ready == 0:
sleep(5)
is_ready = _ping6()
app = SlapOSApp()
# Make sure slapos node format returns ok
is_ready = _runFormat(app)
while is_ready == 0:
print "[BOOT] [ERROR] Fail to format, try again in 15 seconds..."
sleep(15)
is_ready = _runFormat(app)
# Make sure slapos node bang returns ok
is_ready = _runBang(app)
while is_ready == 0:
print "[BOOT] [ERROR] Fail to bang, try again in 15 seconds..."
sleep(15)
is_ready = _runBang(app)
_removeTimestamp(instance_root)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment