I am making a simple visualization tool, that shows the state of some equipment using a few lamps connected to a small computer through a usb relaycard.
The computer runs Debian and the relaycard is a "DenkoviRelayModule".
The basic doing the checking and visualization is basically a loop that runs each 5 seconds. I have gotten the script to function, and can run it.
It would, however, be much better if i could run it in a service-like fashion so i would not need to ssh to the computer each time to start the script. Also, I would like a neat way to run a script whenever the computer shuts down so that the relay state reset.
Having never done any services, I would really like some pointers on how to do it, good practives etc... Note that the script need to run with root permission.
Any hints would be welcome
.... The script in simplified version looks like this.
-----------
#!bin/bash
#Variables
DENKOVI_JAR=/opt/DenkoviRelayCommandLineTool/DenkoviRelayCommandLineTool_10.jar
DENKOVI_SERIAL=Nill
DELAY_SECS=5
#Denkov relaycard needs the ftdi and serial module to be unloaded to function.
#This must be done using root credentials.
rmmod ftdi_sio
rmmod usbserial
#Assuming only one relay is attatched, get its serial.
#All java commands accessing the card must be run as root.
DENKOVI_SERIAL=$(java -jar $DENKOVI_JAR list | awk '{print $1}');
echo Attatched relayboard has serialnumber : $DENKOVI_SERIAL
#simplified version, in actual script servers are checked before setting relay state.
while true; do
java -jar $DENKOVI_JAR $DENKOVI_SERIAL 4 turn 0000
sleep $DELAY_SECS
done