Category Archives: raspberry pi

linux systemd common commands using systemctl

I first used slackware Linux in the early 90s, possibly, and have used Linux quite extensively since then.

The init/service management has changed a lot over that time, from editing /etc/rc.d now to systemd. I have struggled to keep up. So here is a terse set of commands to help me when I come to add or manage services on a Linux box that uses systemd

List all the systemd units ( no need to run as root )

systemctl

List all systemd units, type that have exited

systemctl list-units –type=service –all –state=exited

Show the status of a unit ( you can start, stop, restart, refresh instead of status )

sudo systemctl status owfs

To add a unit:

There seems to be two places that the systemd UNIT files exist.

System installed files are in /lib/systemd/system

User installed files are in /etc/systemd/system

..and there are sometimes symlinks from one to another

to create a new systemd unit called j2

sudo systemctl edit j2.service –force

UNIT file layout

[Unit]
Description=1-wire filesystem FUSE mount
Documentation=man:owfs(1
)

[Service]
Type=notify
NotifyAccess=all
ExecStart=/usr/bin/owfs -c /etc/owfs.conf –allow_other %t/owfs
ExecStop=/usr/bin/umount %t/owfs
RuntimeDirectory=owfs

[Install]
WantedBy=multi-user.target

Enabling your new systemd unit

sudo systemctl enable j2

Raspberry Pi and gpsd ( getting around startup bug )

I need location information for one of my Raspberry Pi devices. I have a USB GPS receiver that appears on /dev/ttyUSB0. To verify the hardware operation, I installed minicom

sudo apt-get install minicom

sudo minicom -s

Then set the port to /dev/ttyUSB0, port parameters to 4800 N8! with no flow control. You should then be able to see NMEA sentences

Once we have proved that the hardware is working, install gpsd.

sudo apt-get install gpsd

sudo dpkg-reconfigure gpsd to set the serial port

Then you have to manually edit the /etc/default/gpsd file and remove /dev/ttyUSB0 from the DEVICES and put it into GPSD_OPTIONS field.

sudo reboot

Once running, you should be able to run cgps -s to see gpsd responding with valid location information.