SCM as a Linux Daemon Example
* 
Not all Unix implementations provide a systemd daemon, such as a Raspberry PI. This example will work only on systems where this daemon is available. A simple test to determine if you have systemd installed is to try running the systemctl command.
The scripts in the ../scm/examples/scm_systemd directory are intended to show you how to install the SCM Edge Extension as a systemd-style service (daemon):
install.sh — Must be run as root. This script will configure the daemon to be in the expected location, /usr/local/bin/scm_client, which is the location to which the scm build command (make install) will copy this application.
start.sh — Starts the installed service.
status.sh — Returns the status, running/stopped of this service.
stop.sh — stops the service.
viewlog.sh — Returns the most recent output of this service.
remove.sh — Removes this service from the configuration of the systemd
Installation
Follow these steps to install and run the examples on a Linux device:
1. Install the ThingWorx Edge C SDK on your device.
* 
Be sure to follow the instructions and use the scripts provided to install the C SDK and the SCM Edge Extension, so that they are installed in the expected library location, /usr/local/lib for the C SDK and /usr/local/bin for the SCM Edge Extension. If you use another location (e.g. /opt/thingworx, you will need to change the LD_LIBRARY_PATH and TWXLIB environment variables to point to the location where you installed the C SDK and SCM in install.sh. In addition, you need to change the executable path to the directory that you used (e.g., /opt/thingworx/bin/scm_client). If you must change the location, refer to Changing the Location after you complete these steps.
To install the C SDK on the device, generate a makefile, using CMake and then run make install to install the C SDK in /usr/local/lib. Here is an example of the commands required to install the C SDK from within the C SDK directory created by extracting the distribution:

>mkdir bin
>cd bin
>cmake ..
>make
>sudo make install
2. Install the SCM Edge Extension.
This procedure is similar to Step 1. You must have the binary for the scm_client application copied to the directory, /usr/local/bin/. You can do this manually or as part of the "make install" process for the SCM extension project. Here is an example of the commands required to install the scm_client application from within the SCM extension project directory:

>mkdir bin
>cd bin
>cmake ..
>make
>sudo make install
3. Edit the config.txt file in the examples/scm_systemd directory.
Before running install.sh you must manually enter the following information in the config.txt file:
Line 0 <service_name>— Enter the name for the service on your system. The default service name is twxscm.
Line 1 <server_hostname>— Type the name of the computer where your ThingWorx platform is running. The value for this parameter is not a URL. It can be a DNS name, localhost, or a numeric IP address.
Line 2 <server_port> — Type the number of the port that your ThingWorx application is using on your sever. Common values are 80, 8080 or 443.
Line 3 <app_key> — Generate an application key using ThingWorx Composer, and copy it to Line 4 in this file. The application key will act as the credentials that this service should use when it connects to the platform.
Line 4 <thingname> — Type the name of the Thing that you have created in ThingWorx to represent this device. It should have the Thing template, TW.RSM.Template.AssetWithTunnelsAndFileTransfer and the following Thing Shapes applied:
TW.RSM.SFW.ThingShape.Updateable
PTC.Resource.Asset.SCMResourceThingShape The value of this Thing Shape will be the name of your device in the SCM console
Line 5 <path_to_whitelist.> — Type the path to the whitelist.txt file to use when processing SCM packages. The default directory is /usr/local/etc/whitelist.txt
Line 6 <staging_directory> — Type the directory to be used for file transfers. The default directory is /var/tmp/staging
The options that you set in this config.txt file are the same as those allowed for the scm_client example application. For details, refer to SCM Client Example
An example of the config.txt file follows:
twxscm
localhost
8080
xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
SampleScmDevice
/usr/local/etc/whitelist.txt
/var/tmp/staging
4. Run the install.sh script.
After verifying that the C SDK and the scm_client are installed to the expected locations, proceed to install the SCM service by running the install.sh script as root to install the service. This script must be run as root and will configure the daemon to be in the expected location, /usr/local/bin/scm_client. The scm build command make install will copy this application to this directory.
5. Now run start.sh to connect to the ThingWorx Platform.
Changing the Location
If you want to change the location that your SCM client executable (/usr/local/bin) or the location you plan to load the SCM extension from (/usr/local/lib), you must manually edit /lib/systemd/system/twxscm.service which was created by the install.sh script.
Here is a sample excerpt from this file:

[Service]
Environment="LD_LIBRARY_PATH=/usr/local/lib"
Environment="TWXLIB=/usr/local/lib"

Type=idle
ExecStart=/usr/local/bin/scm_client -h <address> -p 8080 -k <app_key> -w /etc/whitelist.txt
Changing the value for TWXLIB will allow you to load the SCM extension from a custom directory. Changing LD_LIBRARY_PATH will allow you to set a custom location for your C SDK library files. Changing the ExecStart value will allow you to change the default install location for your scm_client executable.
Was this helpful?