From 8075d7cb3258441fadaf4211c24e8cb668c21ede Mon Sep 17 00:00:00 2001 From: savi_wso2 Date: Sat, 11 Feb 2017 03:17:00 +0530 Subject: [PATCH 1/2] Configuring the Raspberry Pi agent to run as a service --- .../src/main/resources/agent/RaspberryService.sh | 3 ++- .../src/main/resources/agent/src/RaspberryAgent.py | 5 +++-- .../src/main/resources/agent/startService.sh | 4 ++-- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/features/device-types-feature/raspberrypi-plugin-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/agent/RaspberryService.sh b/features/device-types-feature/raspberrypi-plugin-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/agent/RaspberryService.sh index 114226790..8873cac84 100644 --- a/features/device-types-feature/raspberrypi-plugin-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/agent/RaspberryService.sh +++ b/features/device-types-feature/raspberrypi-plugin-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/agent/RaspberryService.sh @@ -15,7 +15,7 @@ DESC="This service is used to publish events from the Raspberry Pi to the WSO2 D NAME=RaspberryStats DIR=/usr/local/src/RaspberryAgent/src/ -DAEMON=python $DIR/RaspberryAgent.py +DAEMON=$DIR/RaspberryAgent.py DAEMON_NAME=$NAME SCRIPTNAME=RaspberryService.sh @@ -39,6 +39,7 @@ DAEMON_USER=root #pi do_start () { log_daemon_msg "Starting system $DAEMON_NAME daemon" start-stop-daemon --start --background --pidfile $PIDFILE --make-pidfile --user $DAEMON_USER --chuid $DAEMON_USER --startas $DAEMON -- $DAEMON_OPTS + python $DAEMON & log_end_msg $? } do_stop () { diff --git a/features/device-types-feature/raspberrypi-plugin-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/agent/src/RaspberryAgent.py b/features/device-types-feature/raspberrypi-plugin-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/agent/src/RaspberryAgent.py index 759a0b6c9..5ab04be85 100644 --- a/features/device-types-feature/raspberrypi-plugin-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/agent/src/RaspberryAgent.py +++ b/features/device-types-feature/raspberrypi-plugin-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/agent/src/RaspberryAgent.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin python """ /** * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. @@ -23,7 +23,8 @@ import logging, logging.handlers import sys, os, signal, argparse import running_mode import time, threading, datetime, calendar -import iotUtils, mqttConnector, Adafruit_DHT, httpServer +import iotUtils, mqttConnector, httpServer +import Adafruit_DHT # import httplib, ssl # from functools import wraps diff --git a/features/device-types-feature/raspberrypi-plugin-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/agent/startService.sh b/features/device-types-feature/raspberrypi-plugin-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/agent/startService.sh index 4ccf64e01..f85bc7a98 100644 --- a/features/device-types-feature/raspberrypi-plugin-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/agent/startService.sh +++ b/features/device-types-feature/raspberrypi-plugin-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/agent/startService.sh @@ -46,9 +46,9 @@ sudo python Adafruit_Python_DHT/setup.py install sudo cp $currentDir/deviceConfig.properties $currentDir/src sudo cp -r $currentDir/src $destination -sudo chmod +x $destination/src/RaspberryAgent.py +sudo chmod 755 $destination/src/RaspberryAgent.py sudo update-rc.d -f RaspberryService.sh remove sudo cp $currentDir/RaspberryService.sh /etc/init.d -sudo chmod +x /etc/init.d/RaspberryService.sh +sudo chmod 755 /etc/init.d/RaspberryService.sh sudo update-rc.d RaspberryService.sh defaults sudo service RaspberryService.sh start From ffee269a0ed27cd09d09d08ecec48d26c2fe80c0 Mon Sep 17 00:00:00 2001 From: lakshani Date: Mon, 20 Feb 2017 14:01:56 +0530 Subject: [PATCH 2/2] Fixed the issue in server startup- removed error logs --- .../mdm/restconnector/internal/MDMComponent.java | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/components/extensions/appm-connector/org.wso2.carbon.appmgt.mdm.restconnector/src/main/java/org/wso2/carbon/appmgt/mdm/restconnector/internal/MDMComponent.java b/components/extensions/appm-connector/org.wso2.carbon.appmgt.mdm.restconnector/src/main/java/org/wso2/carbon/appmgt/mdm/restconnector/internal/MDMComponent.java index c75ed0981..e1830d425 100644 --- a/components/extensions/appm-connector/org.wso2.carbon.appmgt.mdm.restconnector/src/main/java/org/wso2/carbon/appmgt/mdm/restconnector/internal/MDMComponent.java +++ b/components/extensions/appm-connector/org.wso2.carbon.appmgt.mdm.restconnector/src/main/java/org/wso2/carbon/appmgt/mdm/restconnector/internal/MDMComponent.java @@ -37,15 +37,10 @@ public class MDMComponent { protected void activate(ComponentContext context) { BundleContext bundleContext = context.getBundleContext(); + mdmServiceRegistration = bundleContext.registerService(ApplicationOperations.class.getName(), new + ApplicationOperationsImpl(), null); if (log.isDebugEnabled()) { - log.debug("WSO2MDM MDM Component activated"); - } - try { - mdmServiceRegistration = bundleContext.registerService(ApplicationOperations.class.getName(), new - ApplicationOperationsImpl(), null); - } catch (Throwable e) { - log.error("Failed to activate org.wso2.carbon.appmgt.mdm.restconnector.internal." + - "MDMComponent : " + e); + log.debug("WSO2MDM MDM Component activated."); } }