Writing service files in systemd

image source
image source

Systemd may not be the most popular init system out there, and it still manages to annoy me every now and then, but I had a chance to play with it at work recently. A deeper dive into it has left me a little happier with how it handles things.

My requirement was to daemonize a service and have it running at startup. The service has a few command line arguments, and also needs some environment variables set. The command line args could change but should not expect someone to reconfigure the init script. Systemd supported all these requirements out of the box.

Here is what the service file looked like:

[Unit]
 Description=myservice
[Service]
 Environment="LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH"
 EnvironmentFile=/etc/<somefile.cfg>
 ExecStart=/usr/bin/myservice ${arg1} ${arg2} ${arg3}
[Install]
 WantedBy=multi-user.target

The EnvironmentFile has name value pairs of the command line arguments:

arg1=foo
arg2=bar
arg3=baz

There are numerous others configuration parameters for the service. For instance, set Type=oneshot if the application is not a daemon and is going to exit immediately.

Use ExecStartPost for running additional scripts after the first one starts (e.g. maybe you want to write to a pidfile). ExecStartPre, ExecStopPost and ExecStopPre also exist.

The unti file must be present in /etc/systemd/system. To make it run on subsequent boots:

systemctl enable myservice

To start the service:

systemctl start myservice

To check the service’s logs:

journalctl -u myservice

Further reading:

Hello Firefox OS

My wife’s phone broke, so this was the best possible time to get the dirt cheap Intex Cloud FX phone running Firefox OS.

image source
image source

My experience with so far has been unfortunately mediocre. The phone runs on only 256MB, so all expectations with the software must be tempered to account for the limited hardware it runs on. One shouldn’t expect much from a phone that is priced so low, so if you accept it for it is, the experience becomes bearable.

Importing contacts was my only major worry, and was thankfully smooth (I did a Google import). It takes quite a bit of time to open the Contacts App and navigate through it though. Again, this phone teaches you the virtue of patience.

The UI is fairly intuitive, and anyone who has used a touch-based phone before will have no problems settling in.Some apps work pretty nicely, like Notes and Twitter.

I’ve turned off the wifi, I don’t run too many apps that need it. I’m using the phone less and my laptop (and books) more.

If a Firefox OS phone with better hardware was available in India, that would be the one I’d recommend. As it stands, I’ll become a hermit for some time, for a chance to support Mozilla in a small way. I don’t expect phones to last long in my house, with a naughty one year old terrorizing the poor things.

The world’s become a little duller today

image source
image source

Terry Pratchett, Discworld series author, dies aged 66 | Books | The Guardian.

I don’t remember my first Pratchett book, but it didn’t take me long to accumulate pretty much the entire collection.

Like every book nerd, I’ve kept a quotes file that grew over time with tiny bits of text I liked. It shouldn’t be a surprise that a wordsmith like him should figure prominently in it. Here’s one, from Guards! Guards!

It was amazing, this mystic business. You tell them a lie, and then when you don’t need it any more you tell them another lie and tell them they’re progressing along the road to wisdom. Then instead of laughing they follow you even more, hoping that at the heart of all the lies they’ll find the truth. And bit by bit they accept the unacceptable.

And here’s a neat bit of Pratchett trivia: when he was knighted, he forged his own sword, infused with bits of meteorite.

I’m re-reading some old favourites again (starting with Jingo, and moving on to the other Watch novels). Here’s a good reading guide for those getting started.