Category Archives: linux

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

Postfix SSL Certificates on linux

SSL certificates have caught up with us. For our email TLS we used to use self-signed certificates, but that time finally ended when our IOS devices refused to let us authenticate to invalid, expired or self signed certificates.

I have set commercial web sites up with certificates purchased from Godaddy etc when working as a sysadmin. That was 10 years ago, and I’ve forgotten how to do it. This blog is as much of a reminder to myself as a published article .

Do I went to the wonderful letsencrypt people https://letsencrypt.org/

Following the instructions, from a bash shell I installed certbot and it seemed to do everything for me :

  1. created and downloaded a newly signed certificate and key from letsencrypt
  2. configured apache to use it
  3. our jsquared webpage was now secured but this did not help our email
  4. certbot will automatically update the certificate as it expires – I’ll find out if this works in the next few months
  5. It will analyse your apache config and optionally include sub domains as necessary. I needed to manually add the <mail> sub domain that I missed in my first attempt. It seems easy to append a new sub domain later

Configuring postfix to use the new certificates

The normal place to install the certificate is /etc/ssl/certs and for the private key is /etc/ssl/private. We had cert/keys called ssl-cert-snake-oil and I’m guessing that these were the self-signed ones.

certbot installs its keys in /etc/letsencrypt/live/jsquared.co.uk

Certificate: fullchain.pem

Key: privkey.pem

To enable the cert/key for postfix, add/change the following lines in /etc/postfix/main.cf

smtpd_tls_cert_file=/etc/letsencrypt/live/jsquared.co.uk/fullchain.pem
smtpd_tls_key_file=/etc/letsencrypt/live/jsquared.co.uk/privkey.pem

There was a really useful site to test our settings : https://ssl-tools.net/

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.

Installing WordPress

Well, it has been a bit of a bumpy ride for no good reason. Jennifer and I have decided to move our web presence over to wordpress from plain old html/css. To be honest, none of our web pages have been updated for ages. Install WP on our new Ubuntu server ( a VM hosted at Mythic Beasts ) seemed a good and easy idea. I wanted to go with the Ubuntu apt-get install default installation as it should be tried , tested and stable especially using Unbuntu 12.04.

We could not get images uploaded and displayed. I might be the htacces file, misconfiguration in the settings, permissions. We tried a lot of things including upgrading to 14.04LTS.

Jennifer has managed to get WP to display uploaded images using symlinks, but this is not the solution. We have a few other options to try :
1) apt-get remove? wordpress, then install the latest from source from the WP site.
2) hack permalinks. It might help.
3) ask on the WP formums ( there are currently a lot of questions like this )