Skip to content

Commit 8807828

Browse files
committed
Added tut12
1 parent f487a25 commit 8807828

4 files changed

Lines changed: 17 additions & 10 deletions

File tree

README.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,17 @@ Later we will get onto more complicated topics such as reaching a consensus of w
1414

1515
Questions comments and suggestions can be raised the specific blog post or by using issues here.
1616

17-
## Tutorial 11 - Automatic Slave Reconnection
17+
## Tutorial 12 - Automatic Start with rc.local
1818

19-
This tutorial focuses on changing the slave so that it will automatically reconnect to the master if the connection is lost.
19+
This tutorial focuses on modifying our script to automatically start using rc.local.
20+
Some changes will be needed to ensure it works after being run from any location.
2021

21-
With this addition the slave will automatically reconnect to the master no matter how many times it has been restarted. This moves the cluster one step forward towards a system which will automatically repair if there is an issue.
22+
The next tutorial will focus on abstracting the slave code to be more extensible.
2223

23-
The next tutorial will focus on looking at how we can make the cluster code run on boot using rc.local.
24-
25-
The full details for [Tutorial 11 - Automatic Slave Reconnection is available on my blog](https://chewett.co.uk/blog/1964/raspberry-pi-cluster-node-11-automatic-slave-reconnection/)
24+
The full details for
25+
[Tutorial 12 - Automatic Start with rc.local is available on my blog](
26+
https://chewett.co.uk/blog/2002/raspberry-pi-cluster-node-12-automatic-start-with-rc-local/
27+
)
2628

2729
## Requirements
2830

RpiCluster/MainLogger.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
import os
12
import logging
2-
import time
33

44
# First lets set up the formatting of the logger
55
logFormatter = logging.Formatter("%(asctime)s [%(threadName)-12.12s] [%(levelname)-5.5s] %(message)s")
@@ -17,6 +17,6 @@
1717

1818
def add_file_logger(filename):
1919
# Create a handler to store the logs to a file
20-
fileHandler = logging.FileHandler(filename)
20+
fileHandler = logging.FileHandler(os.path.abspath(os.path.join(os.path.dirname(os.path.realpath(__file__)), "..", filename)))
2121
fileHandler.setFormatter(logFormatter)
2222
logger.addHandler(fileHandler)

basic_master.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
#!/usr/bin/env python2.7
22

3+
import os
34
import socket
45
import ConfigParser
56
from RpiCluster.MainLogger import add_file_logger, logger
67
from RpiCluster.RpiClusterClient import RpiClusterClient
78

89
config = ConfigParser.ConfigParser()
9-
config.read('rpicluster.cfg')
10+
config.read(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'rpicluster.cfg'))
1011

1112
socket_port = config.getint("master", "socket_port")
1213
socket_bind_ip = config.get("master", "socket_bind_ip")
@@ -24,3 +25,6 @@
2425

2526
rpiClient = RpiClusterClient(clientsocket, address)
2627
rpiClient.start()
28+
29+
30+

basic_slave.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/usr/bin/env python2.7
22

3+
import os
34
import time
45
import random
56
import ConfigParser
@@ -11,7 +12,7 @@
1112
from RpiCluster.RpiClusterExceptions import DisconnectionException
1213

1314
config = ConfigParser.ConfigParser()
14-
config.read('rpicluster.cfg')
15+
config.read(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'rpicluster.cfg'))
1516

1617
socket_port = config.getint("slave", "socket_port")
1718
master_ip = config.get("slave", "master_ip")

0 commit comments

Comments
 (0)