1

I have Raspberry Pi 2 model B with installed Raspbian Linux. I have to create and start linux service which prints text on LCD Module SC1602a. It looks like this:

[this]

I create my daemon service using Java language 1.8_x86 , Apache Commons Daemon and jsvc. Also I use pi4j project (this is wrapper over WiringPi) to manage Raspberry Pi pins. Java class:

public class Application implements Daemon{
   public static void main(String[] a){
      Application app=new Application();
      app.init(null);
      app.start();
      System.in.read();
      application.stop();
      application.destroy();
   }

   public void init(DaemonContext daemonContext) throws Exception {
        LogUtil.info("Init method...");
        GpioController gpio = GpioFactory.getInstance();
        LogUtil.info("GpioController instance created...");
        GpioLcdDisplay lcd;
        lcd = new GpioLcdDisplay(2, 16, RaspiPin.GPIO_00, RaspiPin.GPIO_02, new Pin[]{RaspiPin.GPIO_03, RaspiPin.GPIO_04, RaspiPin.GPIO_05, RaspiPin.GPIO_06});
        LogUtil.info("LCD instance created...");
        lcd.clear();
        lcd.write(new Date().toString());
        LogUtil.info("Init compeleted:");
   }
   public void start() throws Exception {}
   public void stop() throws Exception {}
   public void destroy() {}
}

I use maven to package my artifact. I Use WinScp to move artifact to Raspberry Pi. When I start this application from command line java -jar application.jar it works well. Application print to LCD module "hello" string. Next I tried to start my application like linux service. I installed jsvc on Raspberry Pi, created script lcd and moved it to folder /etc/init.d/ . Also I wrote chmod +x lcd from folder /etc/init.d. This is my script:

NAME="lcd"
DESC="Lcd Application"
EXEC="/usr/bin/jsvc"
FILE_PATH="/root/lcd"
JAVA_HOME=/usr/lib/jvm/jdk-8-oracle-arm-vfp-hflt
CLASS_PATH="$FILE_PATH/lcd.jar:/usr/share/java/commons-daemon-1.0.15.jar"
CLASS="com.mycompany.Application"
ARGS=""
USER="root"
PID="/var/run/$NAME.pid"
LOG_OUT="$FILE_PATH/$NAME.out"
LOG_ERR="$FILE_PATH/$NAME.err"
jsvc_exec()
{   
    cd $FILE_PATH
    echo $CLASS_PATH
    sudo $EXEC -home $JAVA_HOME -cp $CLASS_PATH -user $USER -outfile $LOG_OUT -errfile $LOG_ERR -pidfile $PID $1 $CLASS $ARGS
}
case "$1" in
   start)
      echo "Starting service LCD"
      jsvc_exec
      echo "Service started"
   ;;

   //many unimportant information

I write command service lcd start. This way doesn't work. In this case application doesn't print on LCD module any information. I opened log files and found next information:

lcd.out:

2015-08-20 12:59:09.934 [INFO] - Init method...

lcd.err:

wiringPiSetup: Unable to open /dev/mem: Operation not permitted Service exit with a return value of 1

As you can see application fails when trying to load pi4j driver. I tried to extend access rules for dev/mem file, I did it and file has rwxrwxrwx but service still not working.

Also I turned off LCD initialization from init() method. Service starts well so service works well without LCD.

Does anybody know the solution? Thanks a lot

Argamidon
  • 337
  • 1
  • 4
  • 15
  • I think this would be better suited on http://raspberrypi.stackexchange.com/ ? It is really specific to Raspbian and from my point of view more a configuration-issue. Maybe you can find something in the wiringPi Docs about how to run it as a daemon? – Fildor Aug 20 '15 at 10:32

0 Answers0