MTConnect Agent on Ubuntu Linux


Before MTConnect can be installed some prerequisites must be in place.  A clean install of Ubuntu 14.04 LTS will not have many of the packages required.  Install these packages using the apt-get command.

$ sudo apt-get install libxml2 libxml2-dev cmake git libcppunit-dev build-essential screen ruby

After all the required packages are in place, the MTConnect source code needs to be downloaded from GutHub.  The source code should compile without any modifcation using cmake and make.

$ cd ~
$ git clone
$ cd cppagent
$ cmake .
$ make

MTConnect Agent Installation

Now that binaries are compiled from the MTConnect source, they just need to be put into appropriate directories.   The agent binary and the configuration file are first.

$ sudo mkdir /etc/mtconnect
$ sudo cp ~/cppagent/agent/agent.cfg /etc/mtconnect/
$ sudo cp ~/cppagent/agent/agent /bin/agent

The source from GitHub contains a script to run MTConnect as a daemon.  I instead opted to write a BASH script that suited my needs a little better.  The script is available at the end of blog.  The blog downloads it from this server.  After it is downloaded it is given permission to execute and added to the startup scripts.

$ cd ~
$ wget
$ sudo mv ~/ /etc/init.d/agent
$ sudo chmod +x /etc/init.d/agent
$ sudo update-rc.d agent defaults

The script requires the user ‘mtconnect’.  So we need to add that user.  Pick a password that is appropriate for you.  For security reasons, you probably should pick a different username and change it in the script, however, this blog uses the default.

$ sudo adduser mtconnect

MTConnect Simulator Installation

The default configuration file that was downloaded with the source code defines a simulator.  For the MTConnect agent to start, it needs to connect to all devices listed in its configuration file.  So now we setup the simulator device.

$ sudo mkdir /etc/mtconnect/simulator
$ sudo rsync -avr ~/cppagent/simulator/ /etc/mtconnect/simulator/

The default configuration file expects the simulator adapter to be one directory above where we placed it.  To correct this, edit the agent.cfg file and point to the correct path for the simulator.

$ sudo nano /etc/mtconnect/agent.cfg

Original Path::  “Devices = ../simulator/VMC-3Axis.xml”

New Path:: “Devices = ./simulator/VMC-3Axis.xml”

Finally, the simulator is started up in a fresh screen.  The simulator blocks the process so just detach the screen using control A, D, after it is up and running.

$ screen -S simulator
$ cd /etc/mtconnect/simulator
$ ruby -v run_scenario.rb -l VMC-3Axis-Log.txt

<cntrl><a> followed by <d>


Testing the MTConnect agent is very simple.  First the agent is started using the script we created, if the script completes successfully we can make sure it is listening for incoming connections.

$ sudo service agent start
$ netstat - tcp -l

Active Internet connections (only servers)
tcp 0 0 *:7878 *:* LISTEN
tcp 0 0 *:5000 *:* LISTEN

With the default configuration the agent is listening on port 5000 and the simulator is listening on port 7878.  If these are listed in the netstat, then everything is good.   For the final confirmation, any browser can be used as client. or



Please let me know any mistakes, omissions or improvements in the code.  It took a great deal of patience to get this up and running, so feel free to ask any questions in the comments.


###### #######

 # /etc/init.d/agent
 # version 0.0.1 2014-05-09 (YYYY-MM-DD)
 # Provides: agent
 # Required-Start: $local_fs $remote_fs
 # Required-Stop: $local_fs $remote_fs
 # Should-Start: $network
 # Should-Stop: $network
 # Default-Start: 2 3 4 5
 # Default-Stop: 0 1 6
 # Short-Description: MtConnect server
 # Description: Starts the MTConnect Agent server

as_user() {
if [ "$USERNAME" != "$ME" ]; then
  su - $USERNAME -c "$1"
  bash -c "$1"

mc_start() {
if netstat - tcp -l | grep -q 5000
  echo "$SERVICE is already running!"
  echo "Starting $SERVICE..."
  as_user "cd $CONFIGPATH && screen -dmS agent $INVOCATION"
  sleep 10
  if netstat - tcp -l | grep -q 5000
    echo "$SERVICE is now running."
    echo "Error! Could not start $SERVICE!"

mc_stop() {
if netstat - tcp -l | grep -q 5000
  echo "Stopping $SERVICE"
  as_user "screen -p 0 -S agent -X stuff \"^C\""
  sleep 10
  echo "$SERVICE was not running."
if netstat - tcp -l | grep -q 5000
  echo "Error! $SERVICE could not be stopped."
  echo "$SERVICE is stopped."

#Start-Stop here
case "$1" in
if netstat - tcp -l | grep -q 5000
  echo "$SERVICE is running."
  echo "$SERVICE is not running."
echo "Usage: $0 {start|stop|status|restart}"
exit 1
exit 0


7 thoughts on “MTConnect Agent on Ubuntu Linux”

  1. Can you help me? Installing MT Connect agent on clean ubuntu 14.04. installation running on ARM. upgraded all packages. followed your instructions. Agent won’t start.

    [detached from 1798.tty1..arm]
    ubuntu@arm:~$ sudo service agent start
    Starting Agent…
    Error! Could not start agent

    port 7878 is listening
    port 5000 doesn’t show in list

    got this message during make:
    /home/ubuntu/cppagent/test/config.test.cpp: in member function ‘void config test::test maxsize ()':

    (same path)::444:43: warning:integer overflow in expression

    cppunit_assert_equal (15 x 1024 x1024 x1024,fl->getmaxsize());

    The only other error i get is:
    starting screen
    run_scenario.rb:41 warning top level constant string referenced by option parser::string

    I also get a message during upgrade telling me that a file (or script, i don’t remember) was updated and newer than the one coming from upgrade. directory it’s pointing at is: /etc/issue/. I am asked to choose to keep or upgrade. I have tried it both ways.

    Any help you can provide would be greatly appreciated.



    1. Hi Jeff,

      Thanks for reading my blog. I’ve never run the agent on ARM before. I would strongly advise to run it directly and not through my script to see what errors it gives. Run the agent directly ‘$agent debug’ and it should give more verbose errors to troubleshoot. Make sense?

      1. Thank you for writing this blog. It has been very helpful. I followed the instructions in your blog except I started the agent: /etc/mtconnect/simulator/agent debug. I received
        22 FATAL [0] init.config: agent failed to load:please be sure the configuation file probe.xml or devices.xml is in the current directory or specify the correct file in the configuration file agent.cfg using Devices = . Those files aren’t in the current directory. Did a whereis. I don’t think they are present on my system but I’m new to Linux. Where should these files be? Thanks.

  2. Hi Jeff,
    The agent.cfg may be the trouble. When the agent starts, it uses the agent.cfg to define many things… including the adapters it will connect to and the styles for displaying data. The agent expects that agent.cfg is in the same directory as the agent binary. You can specify the file as… $\etc\mtconnect\agent debug \etc\mtconnect\agent.cfg. ‘\etc\mtconnect\agent’ is the location of the compiled agent binary, ‘debug’ makes the program verbose, ‘\etc\mtconnect\agent.cfg’ is the location of the config file to pull it all together.

    You also need to make sure the settings inside the agent .cfg are pointing to proper locations and real files :)

    After I’m done moving, I’ll try to post the default directory structure required. Maybe try running in Windows (blah.) before Linux if you are new to the platform. In Windows, just download the binaries and you are ready to go.. Then work on how the .xml and .cfg files work. The knowledge translates directly to the requirements in Linux.

    Welcome aboard, nice to meet someone with similar interests.

Comments are closed.