How do I adapt an init.d script to systemd?

This forum is for topics specific to the Raspberry Pi and Arch Linux ARM

How do I adapt an init.d script to systemd?

Postby welp » Tue Apr 15, 2014 11:08 am

hello!
For a remote personal weather station I've decided to use Arch Linux on R-Pi as it's the distro which takes least space. I've never used Arch before and have a very limited Linux experience/knowledge, so far I've managed to set up pretty much everything I need without much hassle.

However, I'm really stuck with setting up the software daemon to run at boot. I read up on systemd and frankly it's just beyond my comprehension, I also googled for writing custom systemd scripts but it's all too confusing and unclear for me :(

This is the script I need to change:

$this->bbcode_second_pass_code('', '#!/bin/sh
# $Id: weewx.bsd 1485 2013-10-10 20:33:57Z mwall $
# Start script for FreeBSD, contributed by user Fabian Abplanalp
# Adjust app and cfg locations as appropriate, then put this script
# in /usr/local/etc/rc.d
#
WEEWX_BIN="/opt/weewx/bin/weewxd"
WEEWX_CFG="/opt/weewx/weewx.conf"
PIDFILE="/var/run/weewx.pid"

case "$1" in
"start")
echo "Starting weewx..."
/usr/local/bin/python ${WEEWX_BIN} ${WEEWX_CFG} --daemon &
echo $! > ${PIDFILE}
echo "done"
;;

"stop")
echo "Stopping weewx..."
if [ -f ${PIDFILE} ] ; then
kill `cat ${PIDFILE}`
rm ${PIDFILE}
echo "done"
else
echo "not running?"
fi
;;

"restart")
echo "Restarting weewx..."
$0 stop
sleep 2
$0 start
;;

*)
echo "$0 [start|stop|restart]"
;;

esac')

I can easily change the following paths:

WEEWX_BIN="/opt/weewx/bin/weewxd"
WEEWX_CFG="/opt/weewx/weewx.conf
/usr/local/bin/python

other than that I'm really not sure what to do. For example what would be the equivalent of "PIDFILE="/var/run/weewx.pid" ?! I've tried looking for weewx.pid when it's running on my system but it doesn't exist.

From what I gather, after fixing the shell script I'll have to:

a) create a new file: /etc/systemd/system/weewx.service with contents:

$this->bbcode_second_pass_code('', '[Unit]
Description=weewx

[Service]
ExecStart=/usr/bin/weewx

[Install]
WantedBy=multi-user.target ')

b) execute # systemctl enable weewx.service
welp
 
Posts: 14
Joined: Tue Apr 15, 2014 10:26 am

Re: How do I adapt an init.d script to systemd?

Postby crashmaster » Sat Apr 19, 2014 2:22 pm

Your service file is a good start. ;)
See "man systemd.service" for details.
"man -k systemd" shows all systemd relevant things.
crashmaster
 
Posts: 119
Joined: Wed Mar 13, 2013 1:00 am


Return to Raspberry Pi

Who is online

Users browsing this forum: No registered users and 5 guests