How to send a command to a device?

47 views
Skip to first unread message

pni...@gmail.com

unread,
Aug 19, 2020, 12:59:02 PM8/19/20
to OpenWISP
How can i send a command to a device? I think i need to reboot the device when installing https://github.com/openwisp/lua-monitoring/issues/10  to work.

Thanks.

Federico Capoano

unread,
Aug 19, 2020, 1:26:17 PM8/19/20
to OpenWISP
Hi Pedro,

On Wed, Aug 19, 2020 at 11:59 AM pni...@gmail.com <pni...@gmail.com> wrote:
How can i send a command to a device? I think i need to reboot the device when installing https://github.com/openwisp/lua-monitoring/issues/10  to work.

you should not need to reboot the device to install the monitoring scripts into the device, does your firmware have the packages already pre-installed or do you install them by hand or with a script?

The problem may be due to the fact that the current way to install the monitoring scripts is a template which deploys a crontab to the device:
by default, OpenWRT does not contain a crontab file, which will cause the cron process to not start.
When the cron is installed by OpenWISP, the cron process may not be running and the reload script will not start it (because reload operations only reload running processes, they don't start non running processes).

One solution is to include an empty crontab file in the firmware image, which makes cron start and do nothing, but it will work out of the box when installing the template.

Another solution is to ensure the crontab is started at boot with a couple of commands:

touch /etc/crontabs/root
/etc/init.d/cron start


I updated the monitoring template example to include an /etc/rc.local script (executed at boot) which does this.

Regarding sending commands to devices, OpenWISP does not have this feature yet, but it's on my todo list for the next release, I just noticed it was not in the issue list so I created the issue of the things I will be implementing: https://github.com/openwisp/openwisp-controller/issues/253
It's a feature many people have asked, although in my experience, once the system is set up correctly, it will not be really needed, but I understand it's handy for many situations so I'll be working on it.

 I hope this helps to fix the issue you're having! Let me know.

Federico

Federico Capoano

unread,
Aug 19, 2020, 5:35:37 PM8/19/20
to OpenWISP
Clarification:

On Wednesday, August 19, 2020 at 12:26:17 PM UTC-5, Federico Capoano wrote:
[...] 
Regarding sending commands to devices, OpenWISP does not have this feature yet, but it's on my todo list for the next release, I just noticed it was not in the issue list so I created the issue of the things I will be implementing: https://github.com/openwisp/openwisp-controller/issues/253
[...]

Not for the very next release, but for the one afterwards.
There are already many changes going to be released in openwisp-controller 0.8.0, I will work to release the commands feature for the 0.9.0 release.

F.

pni...@gmail.com

unread,
Aug 20, 2020, 3:07:45 AM8/20/20
to OpenWISP
Yes, i need to reboot the device because the cron is stopped. It's not a problem for me, i will compile a custom image with this files installed, but would be great to have an openwrt package or make this optional in openwisp-config.

I don't know if the modified template with /etc/rc.local is a good solution, it also requires a reboot, no?

Regarding sending commands to devices, can be useful in some situations, most times to test things when you are far from the devices. The implementation you have thought of at https://github.com/openwisp/openwisp-controller/issues/253 looks good

Federico Capoano

unread,
Aug 23, 2020, 6:09:03 PM8/23/20
to OpenWISP
On Thursday, August 20, 2020 at 2:07:45 AM UTC-5, pni...@gmail.com wrote:
Yes, i need to reboot the device because the cron is stopped. It's not a problem for me, i will compile a custom image with this files installed, but would be great to have an openwrt package or make this optional in openwisp-config.


I don't know if the modified template with /etc/rc.local is a good solution, it also requires a reboot, no?

Yes, you're right.

We can use one of the openwisp-config hooks: https://github.com/openwisp/openwisp-config/#pre-reload-hook

Maybe the post-registration-hook, since it doesn't need to be done all the time, once the empty crontab is created, if the device is rebooted, cron will start automatically at its next boot.

Eg:

touch /etc/openwisp/post-registration-hook
chmod
+x /etc/openwisp/post-registration-hook

vim
/etc/openwisp/post-registration-hook

#!/bin/sh
touch
/etc/crontabs/root
/etc/init.d/cron start

# save

pni...@gmail.com

unread,
Aug 24, 2020, 2:49:31 AM8/24/20
to OpenWISP
Thanks for talking about hooks, I was unaware of them.

In the end it does not matter, my idea was rather to be able to install openwisp / monitoring in openwrt, and since you always have to connect to install openwisp, at the same time you can make crontab work, one option is that you said, in post- registration-hook.

When monitoring is a package, this will not be necessary.
Reply all
Reply to author
Forward
0 new messages