0

I have a script which is supposed to be executed on boot when the network connection is established (local network would be sufficient). It is the shell version of linphone.

This is my current unit content:

[Unit]
Description=Register Linphone as Client at SIP Server
Requires=network-online.target
After=network-online.target network.target multi-user.target

[Service]
Type=idle
User=pi
ExecStart=/usr/bin/bash /usr/local/bin/service_network/linphonec_init.sh
Restart=on-failure
RestartSec=5

[Install]
WantedBy=default.target

This is the script linphonec_init.sh which is supposed to be executed by the unit:

#! /bin/bash

linphonecsh exit
linphonecsh init
sleep 1
linphonecsh register --host 192.168.1.108 --username 9910 --password 123456
sleep 1
result=$(linphonecsh status register)

if [[ $result == *"identity=sip"* ]]; then
  echo "Registration successful"
  exit 0
else
  echo "Not registered"
  exit 1
fi

First of all: Are both scripts correct? I can't test it right now, but in an earlier version I had no network connection after booting (with Ethernet). My expectation is that this service runs once after the network is only. If it exits successfully it is not started again, otherwise it will be restarted after 5 seconds. Right?

How could I now add a routine which repeatedly checks if the network is available and if not restarts the network interface?

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.