Wednesday, March 29, 2017

moving from inittab to systemd

For better or for worse raspbian has moved from the old System V init process control to the newer systemd version. I liked my inittab file, because it was quite simple and extremely easy to use, but it is no longer a choice.

So, I had this old line in inittab:
Gar:2345:respawn:start-stop-daemon --start -p /tmp/garage.pid  -m --exec /usr/bin/java  -v -d /home/pi/builds -- -jar garageController.jar

And now I want to run it on a new Raspberry Pi.

So, we need to create a service, its actually quite simple. I created the file /etc/systemd/system/garage.service with this text:
[Unit]
Description=Garage Door Control Software

[Service]
Type=simple
PIDFile=/var/tmp/garage.pid
ExecStart=/usr/bin/java -jar garageDoor.jar gpio
#ExecStart=/home/pi/builds/start_controller.sh
WorkingDirectory=/home/pi/builds
Restart=always

[Install]
WantedBy=multi-user.target

Then we need to run a few commands to make sure our new service auto-starts.

sudo systemctl daemon-reload

sudo systemctl enable garage.service
sudo systemctl start garage.service

sudo systemctl --all | grep garage
##this should show that the service is started.


That's it. 

(I used instructions from https://n3mesisfixx.blogspot.ie/2012/08/migrate-etcinittab-job-to-systemd-in.html)

Monday, March 13, 2017

Raspberry pi wont update time on NTP

Weird problem with a pi zero-w, where when I put it on my friend's network it gets the wrong time.


Bit of a workaround, rather than a fix, but it got me up and running, and should be reliable...

  1. Open rc.local file
    sudo nano /etc/rc.local
  2. add following line to the rc.local file
    sudo date -s "$(wget -qSO- --max-redirect=0 google.com 2>&1 | grep Date: | cut -d' ' -f5-8)Z"
  3. reboot the Rpi
    sudo reboot
Basically, it gets the HTTP headers from the server at google.com and sets the pi's time to that.




From:
https://raspberrypi.stackexchange.com/questions/47542/raspberry-pi-wont-update-time