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
#!/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
# 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: pam_unix(sudo:session): session opened for user root by (uid=0) Apr 10 19:54:04 raspberrypi sudo: pam_unix(sudo:session): session closed for user root Apr 10 19:54:04 raspberrypi sudo: root : TTY=unknown ; PWD=/home/pi/ns3-hw ; USER=pi ; COMMAND=/usr/bin/git fetch origin Apr 10 19:54:04 raspberrypi sudo: pam_unix(sudo:session): session opened for user pi by (uid=0) Apr 10 19:54:04 raspberrypi rc.local: fatal: unable to access 'https://github.com/myuser/repo/': Could not resolve host: github.com Apr 10 19:54:04 raspberrypi sudo: pam_unix(sudo:session): session closed for user pi Apr 10 19:54:04 raspberrypi systemd: rc-local.service: Control process exited, code=exited status=128 Apr 10 19:54:04 raspberrypi systemd: Failed to start /etc/rc.local Compatibility. Apr 10 19:54:04 raspberrypi systemd: rc-local.service: Unit entered failed state. Apr 10 19:54:04 raspberrypi systemd: 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.