question

schnema avatar image
schnema asked

MultiPlus 2 GX run own script at startup

Hello everyone,


On my Multiplus 2 GX I try to run a script at every boot. It is a .armv7 file to read SMA Home Manager 2.0 data. The script works well if I start it over an SSH session. But once disconnected, it stops to work. My goal is to start the shm-et340 script at every boot. But I am not able to run it.


I first have tried to find out how the GX boot works. If I am correct, file in /etc/init.d/ is required. But form here I am not sure anymore.

However, the file I made has this content and is called Energymeter (with no ending). The file is chmod + x and has this content:


#!/bin/sh

# chkconfig: 2345 40 80

### BEGIN INIT INFO
# Provides: shm-et340
# Required-Start: $local_fs $all
# Required-Stop:
# Default-Start: 2345
# Default-Stop:
# Short-Description: Start daemon at boot time
### END INIT INFO

PATH=/data/home/root/
NAME=shm-et340
DESC=SMA Homemanager 2.0 -> Victron EM340 faker



Afterwards I made the following: update-rc.d /etc/init.d/Energymeter defaults


However, after a reboot it is not working and no energydata is publisehed.


May please someone help me or give me a hint what to look for?


Best regards

Marc

Multiplus-IIVRM
2 |3000

Up to 8 attachments (including images) can be used with a maximum of 190.8 MiB each and 286.6 MiB total.

4 Answers
schnema avatar image
schnema answered ·

Thanks again to mitchese.


I do not understand what @stefanie code link is for.


Anyone struggeling over this thread.


create /data/rc.local

!#/bin/bash

sleep 15
setsid /data/home/root/shm-et340 > /dev/null 2>/dev/null &

you may want to replace shm-et340 with your filename.

4 comments
2 |3000

Up to 8 attachments (including images) can be used with a maximum of 190.8 MiB each and 286.6 MiB total.

bathnm avatar image bathnm commented ·

the key is the first line

  1. !#/bin/bash


Without this the system does not know to do with the file. It tells the system to interpret the rest of the contents as a bash shell script.

For others there are two files that can be used to start programs at boot. the file /boot/rcS.local is run very early in the startup sequence, then /data/rc.local is run after all the rest of the unix and Venus system is running.

Both of them need to be unix shell scripts.

Be aware that VenusOS does not always follow standard Linux/Unix startup methodologies such as init.d, system.d, etc.

You can also start things by creating a directory under /services/. Take a look at other directories within this area to understand what you need. it is based on daemontools

0 Likes 0 ·
schnema avatar image schnema bathnm commented ·

@Bathnm

May you add an example for rc.local? Or is the code without the sleep correct?



  
                     
  1. !#/bin/bash
  2. setsid /data/home/root/shm-et340 > /dev/null 2>/dev/null &

I ask, because there are others on github looking for a reliable example.

1 Like 1 ·
bathnm avatar image bathnm schnema commented ·

This should be enough...

  1. !#/bin/bash
  2. /data/home/root/shm-et340


Juts make sure that the executable bit of both the rc.local and the file called has been set.

You can check by looking at the output of ls -al.

0 Likes 0 ·
schnema avatar image schnema bathnm commented ·

it works too but does not show the AC loads. I keep mitchese solution.

https://github.com/mitchese/shm-et340

0 Likes 0 ·
Stefanie (Victron Energy Staff) avatar image
Stefanie (Victron Energy Staff) answered ·

Hi @schnema,

please have a read at Venus OS: Root Access to install/run own code at boot.

2 |3000

Up to 8 attachments (including images) can be used with a maximum of 190.8 MiB each and 286.6 MiB total.

schnema avatar image
schnema answered ·

Thanks Stefanie,


But the description is not enought for my linux knowledges.

When custom-rc.d is installed,

How to do it? Just save a file?


So I have to create the /data/rc.local file. There in this file I need to place the execution order? There are no examples provided :-(

The rc.local has only the following line to run my script then?


/data/home/root/shm-et340



***Edit 1***

I created a the /data/rc.local file with the following line of code:

./data/home/root/shm-et340


This does not start the shm-et340 script after a reboot.

***Edit 2 ***

not working with the line:
/data/home/root/shm-et340


***Edit 3 ***

not working with the lines:
/data/home/root/shm-et340.sh

./data/home/root/shm-et340.sh

2 comments
2 |3000

Up to 8 attachments (including images) can be used with a maximum of 190.8 MiB each and 286.6 MiB total.

I'm not the linux expert either, but there are so many tutorials in the internet. Should be easy to find out.

Example: look for bash scripting for beginners. Ask Ubuntu is always a good source for beginner questions: How to run a script in rc.local

A couple of tips, that will hopefully help to get started:

Create the script you want to execute on start.
Make sure you can run your script manually without rc.local first (make it executable).
It's always good to have an exit code at the end of your script so that you know if something gets wrong.


0 Likes 0 ·
schnema avatar image schnema Stefanie (Victron Energy Staff) ♦♦ commented ·

Yeah, as I mentioned above. The script works if executed.


You are totally right, there are many tutorials. I spent at least 6 hours reading tutorials an try+error. I am sure, it will be a small thing only.

0 Likes 0 ·
panamax avatar image
panamax answered ·

Good day.... im stuck at the very same position... have you been able to add the SHM Faker to the Autostart funktion in the Meantime?


Hope you can help!

2 |3000

Up to 8 attachments (including images) can be used with a maximum of 190.8 MiB each and 286.6 MiB total.

Related Resources