1

I am trying to make my script initialize with beaglebone in the boot process. For that, I use systemctl initialization process.

My service is placed in /lib/systemctl/system with the name autostart-scripts.service and the content is:

[Unit]
Description=Autostart Scripts

[Service]
Type=oneshot
ExecStart=/home/init-usb-internet.sh

[Install]
WantedBy=multi-user.target

As you can see my script is placed in hokme and its content is:

#!/bin/sh
echo "Autoconfiguring internet on micro USB connection"
echo "Setting up the default gateway"
/sbin/route add default gw 192.168.7.1

echo "Updating the nameserver entry"
echo "nameserver 8.8.8.8" >> /etc/resolv.conf

echo "Setting the time using the Irish ntp pool"
/usr/bin/ntpdate -b -s -u ie.pool.ntp.org

And it is not working, I follow the steps registering the service in systemctl with enable but for some reason it has problem in the execution at begining.

The systemctl status is this:

● autostart-scripts.service - Autostart Scripts
   Loaded: loaded (/lib/systemd/system/autostart-scripts.service; enabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Wed 2018-02-21 16:26:43 UTC; 7min ago
  Process: 852 ExecStart=/home/init-usb-internet.sh (code=exited, status=127)
 Main PID: 852 (code=exited, status=127)

Feb 21 16:26:42 beaglebone init-usb-internet.sh[852]: Autoconfiguring internet on micro USB connection
Feb 21 16:26:42 beaglebone init-usb-internet.sh[852]: Setting up the default gateway
Feb 21 16:26:42 beaglebone init-usb-internet.sh[852]: SIOCADDRT: Network is unreachable
Feb 21 16:26:42 beaglebone init-usb-internet.sh[852]: Updating the nameserver entry
Feb 21 16:26:42 beaglebone init-usb-internet.sh[852]: Setting the time using the Irish ntp pool
Feb 21 16:26:42 beaglebone init-usb-internet.sh[852]: /home/init-usb-internet.sh: 10: /home/init-usb-internet.sh: /usr/bin/ntpda
Feb 21 16:26:43 beaglebone systemd[1]: autostart-scripts.service: Main process exited, code=exited, status=127/n/a
Feb 21 16:26:43 beaglebone systemd[1]: Failed to start Autostart Scripts.
Feb 21 16:26:43 beaglebone systemd[1]: autostart-scripts.service: Unit entered failed state.
Feb 21 16:26:43 beaglebone systemd[1]: autostart-scripts.service: Failed with result 'exit-code'.

Update 1:

I remove synchronization time command and add After=network-online.target in [Unit] section and the problem still existing. The new status is this, I think problem is related to network communication. Probably it is executing first than other important network service.

[sudo] password for debian:
● autostart-scripts.service - Autostart Scripts
   Loaded: loaded (/lib/systemd/system/autostart-scripts.service; enabled; vendor preset: enabled)
   Active: inactive (dead) since Thu 2018-02-22 10:06:07 UTC; 1min 36s ago
  Process: 947 ExecStart=/home/init-usb-internet.sh (code=exited, status=0/SUCCESS)
 Main PID: 947 (code=exited, status=0/SUCCESS)

Feb 22 10:06:07 beaglebone systemd[1]: Starting Autostart Scripts...
Feb 22 10:06:07 beaglebone init-usb-internet.sh[947]: Autoconfiguring internet on micro USB connection
Feb 22 10:06:07 beaglebone init-usb-internet.sh[947]: Setting up the default gateway
Feb 22 10:06:07 beaglebone init-usb-internet.sh[947]: SIOCADDRT: Network is unreachable
Feb 22 10:06:07 beaglebone init-usb-internet.sh[947]: Updating the nameserver entry
Feb 22 10:06:07 beaglebone systemd[1]: Started Autostart Scripts.
  • Try adding in the [Unit] part After=network-online.target – meuh Feb 21 '18 at 18:03
  • Didn't work. Also I remove synchronization time command and problem still existing. – Jefferson Alexis Feb 22 '18 at 10:11
0

I can solve!

There were 3 problems in my work.

1st [critical=low] The folder for ntpdate was not correct, hence my sh script got a error in this line, I removed that and I will search for the correct folder and I will test again for time auto synchronization time on booting.

2nd [critical=high] I did not specify a Type field in [Service], hence systemd was assuming the Type=simple which is not correct for my task. I need that my script execute after all the peripherals, services and targets and for that I need to specify with Type=idle.

3rd [critical=high] As I need network communication for my script I need to add After=network.service in [Unit].

Also I give execution permission and make a daemon-reload. and now it is working. I am attaching the working service code.

[Unit]
Description=Autostart Scripts
After=network.target

[Service]
Type=idle
ExecStart=/home/init-usb-internet.sh

[Install]
WantedBy=multi-user.target

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.