Running the Python Device Manager in a Production Environment
To run the device manager in a production environment, you may want to change the configuration to follow the conventions of the operating system on which you run the device manager.
For example, in Linux, you may want to use /etc for configuration, /var/lib for run-time files, and run the device manager from a system directory, such as /usr/bin or /usr/local/bin. If you configure all your applications to use the same configuration directory, it ensures that your applications use the same device_id file and you can easily identify all applications on the same device on the Management Portal. You must also create a user under which the device manager runs and add the user to the sudoers list with the required commands included.
In Windows, you may want to create a folder under C:\Program Files that contains the executable files required for all your device applications and create a folder under C:\ProgramData for configuration and run-time files.
If you include the Device Cloud agent components in your image for Yocto-based Linux distributions by adding the meta-device-cloud layer to your build, the device manager is already configured to run in a production environment. Configuration files are located in the /etc/python-device-cloud directory, run-time files are located in the /var/lib/python-device-cloud directory, it runs as the dc user, and it starts automatically as a service using systemd or sysvinit. Therefore, most of the steps in this section are not necessary. However, you still need to create the iot-connect.cfg file in the /etc/python-device-cloud, and you may want to customize the iot.cfg file and add custom attributes in the attributes.cfg file.
For other distributions, the device manager does not start automatically. You may want to run the application as a service to start it when the device starts and automatically restart it if it fails.
You need the device manager connection configuration file you generated. For more information, see the following:
- Generating the Device Manager Connection Configuration File in Linux
- Generating the Device Manager Connection Configuration File in Windows
You need a new thing definition and application for your device manager defined in Device Cloud.
When the device manager runs, the agent searches the specified configuration directory for the device_id, iot-connect.cfg, iot.cfg, and attributes.cfg files. The device manager appears as a thing with the thing key deviceId-device_manager_py on the Things page on the Management Portal. If you ran the device manager previously with the default configuration directory, the agent generates a new device_id file and the device manager uses a new thing key.
If you want all your applications on the device to share a common configuration directory, ensure that you specify the same directory when you initialize your other applications (see Initializing Your Python Application) and store the application-specific connection configuration file in the configuration directory.