-1

I think I'm having part terminology problem, part just plain newb problem, part tired of reading problem.

I've gotten so far on my home energy monitor project, from getting my SDR radio working, decoding the data, pushing json to InfluxDB, running Grafana and getting graphs! All through googling as I have less than 2 months Linux experience (just playing with Raspberry Pi/OrangePi.

My OrangePi runs Armbian Ubuntu 16.04

I need a very simple "command" to execute at boot. It will be running all the time in the background. So I guess that makes it a daemon? The command is

/home/jonboy545/GoCode/bin/rtlamr -filterid=62059972 -format=json -msgtype=idm unique=true | rtlamr-collect

That's it. I made a simple script called log_energy.sh, made it executable. It's just:

#!/bin/bashr
/home/jonboy545/GoCode/bin/rtlamr -filterid=62059972 -format=json -msgtype=idm unique=true | rtlamr-collect;

If I type ./log_energy.sh into a terminal window, everything works great. I have to open a SCREEN instance, so I can detach it so I don't have to leave the terminal open. Obviously this isn't the best solution.

So, do I put this into rc.local? I had some issues, I think it's executing too soon, so I tried putting a sleep 60 in there but it still was sporadic. Sometimes it worked, sometimes it didn't. So I thought about using crontab and just have it execute @reboot. Again, probably not the best solution. Also there are environment variables that must be declared and are set in ~/.profile (I guess they could go anywhere) and I'm not sure that crontab "reads" those environment variables, atleast that's what I've read.

So what's the "proper" way to have this script execute at boot (maybe at the very end, once everything has "settled down."

Ultimately I'd like to have it as a "service" called "energylog" so I could do a sudo service energylog start/stop/restart.

I've looked at /etc/init.d/skeleton as well as some already existing files in /etc/init.d but I'm not really sure what I'm looking at.

Can somebody steer me in the right direction?

Many thanks!

1 Answer 1

3

I guess part of the problem is there are/have been a few ways to run an application at startup.

A daemon is something like the old DOS TSRs - its an application that's started and runs at the background.

The "classic" ways to do this with an init script (which tend to be a little complicated to write) - but these have been somewhat obsoleted, or crontab - which literally just a thing designed to run specific tasks at a time.

The service command refers to upstart, which handles what init scripts did, but with 16.04, its replaced by systemd. Its used for systemd for folks transitioning from upstart but its worth replacing "service" with "systemctl" - which does the same thing, and more.

Write your script for systemd.

Why? Its supported, and will be for the long run. Its got a pretty sensible syntax. Documentation is also actually fairly decent.

Also there are environment variables that must be declared and are set in ~/.profile (I guess they could go anywhere) and I'm not sure that crontab "reads" those environment variables, atleast that's what I've read.

As per the systemd docs (and for further reading - this AU question, and Ubuntu's documentation)

You can add a line with the environmental variables with a line like

Environment="ONE=one" 'TWO=two two'

You can also start it as a specific user, or at a specific time. You can even trivially restart it automatically

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .