[systemd-devel] Recommendation for "systemd.module" unit

Larry Baker baker at usgs.gov
Thu Jan 24 14:08:35 PST 2013


I am converting the init script (see below) for Linux DECnet (http://sourceforge.net/projects/linux-decnet).  This is my first exposure to systemd.  Naturally, my first try failed.  So, now I am taking baby steps.

The Linux DECnet init script can start either or both the dnetd or phoned daemons.  (I do not use the phoned daemon.)  I think the best thing to do with smartd is make them separate service units.  I will create /etc/systemd/system/dnetd.service and .../phoned.service.

Prior to starting the daemons, the init script verifies the /etc/decnet.conf configuration file exists.  I will use the [Unit] option ConditionFileNotEmpty=/etc/decnet.conf to replicate that behavior.

Then it looks for evidence that the decnet kernel module is loaded by testing for the file /proc/net/decnet.  If necessary, it loads the decnet kernel module and checks again for /proc/net/decnet.  I have already built the decnet kernel module and I can load it with modprobe.  I do not wish to force an unconditional load of the decnet kernel module using /etc/modules-load.d/decnet.conf; I prefer the services that need it (dnetd and phoned) trigger the load.  However, I find no mention of the standard systemd "load a kernel module" practice.  I.e., there is no "systemd.module" unit.  What is the recommended method in the systemd framework to trigger a unit that loads a kernel module?  If the modprobe command fails, I presume that will cause the systemd start command to fail.  I would also like the systemd start command to fail if /proc/net/decnet is not created (a sign that the module has not initialized itself correctly).  Is there a syntax in a systemd unit for that as well?

Thank you in advance for your advice.

Larry Baker
US Geological Survey
650-329-5608
baker at usgs.gov


#!/bin/sh
#
# decnet.sh
#
# Starts/Stops DECnet processes
#
# chkconfig: - 09 91
# description:  DECnet.
# processname: dnetd
# config: /etc/decnet.conf
#
#
# This script should go in
#  /etc/init.d for redhat 7.0 onwards
#  /etc/rc.d/init.d for redhat up to 6.2
#
# You can install it using the following command:
#
# chkconfig --level 345 decnet on
#
# -----------------------------------------------------------------------------
#
# Daemons to start. You may remove the ones you don't want
#
#daemons="dnetd phoned"
daemons="dnetd"

# Prefix for where the progs are installed. "make install" puts them
# in /usr/local, the RPM has them in /usr
prefix=/usr/local

#
# Interfaces to set the MAC address of. By default only the default interface
# in /etc/decnet.conf will be set. If you want to set up more interfaces
# for DECnet than add them here.
#
extra_interfaces=""

#
# Set up some variables.
#
. /etc/rc.d/init.d/functions
startcmd="daemon"
stopcmd="killproc"
startendecho=""
stopendecho="done."

case $1 in
   start)
     if [ ! -f /etc/decnet.conf ]
     then
       echo $"DECnet not started as it is not configured."
       exit 1
     fi

     # If there is no DECnet in the kernel then try to load it.
     if [ ! -f /proc/net/decnet ]
     then
       modprobe decnet
       if [ ! -f /proc/net/decnet ]
       then
         echo $"DECnet not started as it is not in the kernel."
	 exit 1
       fi
     fi

     echo -n $"Starting DECnet: "

     NODE=`grep executor /etc/decnet.conf| awk '{print $2}'`
     echo "$NODE" > /proc/sys/net/decnet/node_address
     CCT=`grep executor /etc/decnet.conf | awk '{print $6}'`
     echo "$CCT" > /proc/sys/net/decnet/default_device
     $prefix/sbin/setether $NODE $CCT $extra_interfaces 

     for i in $CCT $extra_interfaces
     do
       ip link set dev $i allmulticast on
     done



     for i in $daemons
     do
       $startcmd $prefix/sbin/$i
       echo -n $" `eval echo $startecho`"
     done
     echo $"$startendecho"
     ;;

   stop)
     echo -n $"Stopping DECnet... "
     for i in $daemons
     do
       $stopcmd $prefix/sbin/$i
     done
     echo $"$stopendecho"
     ;;

   restart|reload|force-reload)
     echo -n $"Restarting DECnet: "
     for i in $daemons
     do
       $stopcmd $prefix/sbin/$i
       $startcmd $prefix/sbin/$i
       echo -n $"$startecho"
     done
     echo $"$stopendecho"
     ;;

   *)
     echo $"Usage $0 {start|stop|restart|force-reload}"
     ;;
esac

exit 0

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/systemd-devel/attachments/20130124/41d882d0/attachment.html>


More information about the systemd-devel mailing list