0

I want my Pi to fetch and update the local repository according to any changes from the remote repo at github.com

I feel like my rc.local is being executed before there's network connectivity. Here is what I have:

This is my /etc/rc.local:

#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.

# Print the IP address
_IP=$(hostname -I) || true
if [ "$_IP" ]; then
  printf "My IP address is %s\n" "$_IP"
fi

sudo ip link set wlan0 promisc on

cd /home/pi/repo
git fetch origin (also failed: sudo -u pi git ...)
git reset --hard origin/master
cd

exit 0

In an attempt to make rc.local wait for connection, this is my /lib/systemd/system/rc-local.service:

#  This file is part of systemd.
#
#  systemd is free software; you can redistribute it and/or modify it
#  under the terms of the GNU Lesser General Public License as published by
#  the Free Software Foundation; either version 2.1 of the License, or
#  (at your option) any later version.

# This unit gets pulled automatically into multi-user.target by
# systemd-rc-local-generator if /etc/rc.local is executable.
[Unit]
Description=/etc/rc.local Compatibility
ConditionFileIsExecutable=/etc/rc.local
Wants=network-online.target
After=network.target network-online.target (also tried without network.target)

[Service]
Type=forking
ExecStart=/etc/rc.local start
TimeoutSec=0
RemainAfterExit=yes
GuessMainPID=no

When looking at the service status, I get this:

$ sudo systemctl status rc.local
● rc-local.service - /etc/rc.local Compatibility
   Loaded: loaded (/lib/systemd/system/rc-local.service; static; vendor preset: enabled)
  Drop-In: /lib/systemd/system/rc-local.service.d
           └─debian.conf
        /etc/systemd/system/rc-local.service.d
           └─ttyoutput.conf
   Active: failed (Result: exit-code) since Tue 2018-04-10 19:54:04 UTC; 8min ago
  Process: 428 ExecStart=/etc/rc.local start (code=exited, status=128)

Apr 10 19:54:04 raspberrypi sudo[432]: pam_unix(sudo:session): session opened for user root by (uid=0)
Apr 10 19:54:04 raspberrypi sudo[432]: pam_unix(sudo:session): session closed for user root
Apr 10 19:54:04 raspberrypi sudo[450]:     root : TTY=unknown ; PWD=/home/pi/ns3-hw ; USER=pi ; COMMAND=/usr/bin/git fetch origin
Apr 10 19:54:04 raspberrypi sudo[450]: pam_unix(sudo:session): session opened for user pi by (uid=0)
Apr 10 19:54:04 raspberrypi rc.local[428]: fatal: unable to access 'https://github.com/myuser/repo/': Could not resolve host: github.com
Apr 10 19:54:04 raspberrypi sudo[450]: pam_unix(sudo:session): session closed for user pi
Apr 10 19:54:04 raspberrypi systemd[1]: rc-local.service: Control process exited, code=exited status=128
Apr 10 19:54:04 raspberrypi systemd[1]: Failed to start /etc/rc.local Compatibility.
Apr 10 19:54:04 raspberrypi systemd[1]: rc-local.service: Unit entered failed state.
Apr 10 19:54:04 raspberrypi systemd[1]: rc-local.service: Failed with result 'exit-code'.
Warning: rc-local.service changed on disk. Run 'systemctl daemon-reload' to reload units.

I am not sure why it is not waiting for the network to be up and running. Any idea? If I run sudo /etc/rc.local start after boot, it executes and updates my files.

3
  • 1
    Using an obsolete SysV script on systemd is not recommended - it says "This script is executed at the end of each multiuser runlevel" - which is meaningless on systemd. Having said that, I cannot see anything wrong with the script. If you want to wait for networking set in raspi-config. – Milliways Apr 10 '18 at 23:00
  • Make a clean service for your updates to start with systemd. Fiddling in from systemd emulated SysV may break its normal emulation in general. – Ingo Apr 11 '18 at 18:24
  • My workaround is to simply sleep 10 before I do any git command. For me, that is enough, though. How do I create a service just for this? Do you have a link to a tutorial I could follow? – regisin Apr 11 '18 at 21:19

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.