# Factory Proxy Start/Stop
Factory Proxy components and business modules run as Linux containers. They are managed by the Docker Swarm orchestrator. There can occure some situations where you'd want to completely stop the containers from operating, for example due to some maintenance operations.
# Stopping
To stop a specific Docker Swarm service, you can achieve that by scaling that service down to 0 replicas:
$ docker service scale {service}=0
In the case of Factory Proxy you'd have to run such a command for:
- factory-proxy
- factory-broker
- your business modules
In a typical deployment, that would be a minimum of three services.
Here's an example of that:
$ sudo docker service scale factory-proxy=0
factory-proxy scaled to 0
overall progress: 0 out of 0 tasks
verify: Service converged
$ sudo docker service scale factory-broker=0
factory-broker scaled to 0
overall progress: 0 out of 0 tasks
verify: Service converged
$ sudo docker service scale reference-BL=0
reference-BL scaled to 0
overall progress: 0 out of 0 tasks
verify: Service converged
# Starting
When your maintnance is done and you want to start Factory Proxy operation again, you can scale the services back to the default 1 replica:
$ docker service scale {service}=1
Again, such a command would have to be invoked for all the services running on your machine.
Here's a typical example:
$ sudo docker service scale reference-BL=1
reference-BL scaled to 1
overall progress: 0 out of 1 tasks
1/1: runnning [==================================================>]
verify: Service converged
$ sudo docker service scale factory-broker=1
factory-broker scaled to 1
overall progress: 0 out of 1 tasks
1/1: runnning [==================================================>]
verify: Service converged
$ sudo docker service scale factory-proxy=1
factory-proxy scaled to 1
overall progress: 0 out of 1 tasks
1/1: runnning [==================================================>]
verify: Service converged
MQTT Connection
The order of services starting up is not guaranteed. It could happen that your business module starts before the factory-broker server starts fully operating. In such a case, the MQTT connection might not be established successfully. Your module should handle such a case on startup.
Note that the advise above does not only apply to the specific operation of manually starting/stopping of the services. The containers under orchestration should generally be resistant to connection issues via retry logic.
# Housekeeping Service
It's worth noting that there is also a systemd service called abb-factory-proxy-housekeeping that is installed on all Factory Proxy machines. Its purpose is to keep the machine clean from old Docker artifacts (images/containers) that are not needed anymore. It runs every 10 minutes and removes all dead containers and unused container images.
When combined with the manual stop/start operation (described above), it might cause the removal of all Factory Proxy related images from the system. These images would be redownloaded as soon as we start the services back. Such a behaviour might be undesired due to various reasons (like slow network speeds).
To circumvent the deletion of the images, you might want to stop the housekeepeing service before scaling down the Swarm services. Here's how you'd do it:
systemctl stop abb-factory-proxy-housekeeping.timer
systemctl disable abb-factory-proxy-housekeeping.timer
Then, when the maintenance is done, and you'd want to reenable the housekeeping schedule, you can do it as follows:
systemctl enable abb-factory-proxy-housekeeping.timer
systemctl start abb-factory-proxy-housekeeping.timer
# Script Example
In the previous sections we've presented some general steps of how you can start/stop the Factory Proxy services. The steps normally include some interactions with the Docker Swarm and systemd.
To make the start/stop operations a bit easier, you could "package" these commands into their own script files:
# start.sh
#! /bin/bash
set -euo pipefail
docker service ls --format '{{.Name}}' | while read service ; do
docker service scale "$service"=1
echo
done
systemctl enable abb-factory-proxy-housekeeping.timer
systemctl start abb-factory-proxy-housekeeping.timer
# stop.sh
#! /bin/bash
set -euo pipefail
systemctl stop abb-factory-proxy-housekeeping.timer
systemctl disable abb-factory-proxy-housekeeping.timer
echo
docker service ls --format '{{.Name}}' | while read service ; do
docker service scale "$service"=0
echo
done
Permissions
Make sure the files are executable with chmod u+x start.sh stop.sh
.
Additionally, the scripts require root privileges when executing. Preferably,
use sudo
to execute the files.
The scripts dynamically fetch the list of configured Docker Swarm services, so in typical situations you do not need to input the names of your specific business modules.
Restart
In order to just restart Factory Proxy services you could run sudo ./stop.sh && sudo ./start.sh
. You could also just create a third script called restart.sh
that invokes stop.sh
and start.sh
internally.
# Summary
The presented information should help you in maintenance situations where you
might want to stop Factory Proxy operations for some time. The presented
start.sh
/stop.sh
scripts are exemplary and they have not been
production-tested.