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)

1 comment:

Magenta said...

Helpful guide. great job!