Permalink
Browse files

Merge branch 'systemd'

  • Loading branch information...
2 parents 5d02ae0 + f753c11 commit 4ec3881e2622bd00b0d6438b88bb1d7488b703e0 @Ratler committed Jul 31, 2012
Showing with 176 additions and 68 deletions.
  1. +1 −5 Makefile
  2. +175 −63 lnet/lnet
View
6 Makefile
@@ -9,7 +9,7 @@ VERSION = 2012.1
PROGRAMS = lids/lids luser/luser lnet/lnet lservices/lservices \
lmodules/lmodules clad/clad ltime/ltime
-DOCS = README COPYING ChangeLog
+DOCS = README COPYING
MANPAGES = lnet/lnet.8
PROFILEDFILES = clad/clad.rc
@@ -51,9 +51,5 @@ install:
install -m644 $${DOC} ${DOCDIR}/ ; \
done
-log:
- rm -f ChangeLog
- svnlog > ChangeLog
-
dist:
git archive --format=tar --prefix=lunar-tools-$(VERSION)/ lunar-tools-$(VERSION) | bzip2 > lunar-tools-$(VERSION).tar.bz2
View
238 lnet/lnet
@@ -1,6 +1,6 @@
#!/bin/bash
############################################################
-# Copyright 2002-2005 The Lunar Linux Team #
+# Copyright 2002-2012 The Lunar Linux Team #
############################################################
# lnet is a menu driven configurator for the networking #
# init script #
@@ -10,6 +10,8 @@
# Just kidding. This is an adaption of the network config #
# contained within the Lunar install script. #
# #
+# Copyright 2012 by Stefan Wold #
+# #
# this code is GPLv2 #
############################################################
@@ -51,28 +53,83 @@ goodbye() {
}
get_dev_list() {
- /bin/ls -1 $CONFIG_DIR | sort
+ ls -1 $CONFIG_DIR | sort
}
get_dev_status() {
- L=`/sbin/ifconfig | grep "^$1[[:space:]]" | wc -l | tr -d ' \t\n'`
- if [[ "$L" -eq "0" ]]; then
+ if ip link show $1 | grep -q 'state DOWN'; then
echo "[DOWN]"
else
- echo "[_UP_]"
+ echo "[ UP ]"
+ fi
+}
+
+systemd_disable_existing() {
+ for i in $(ls -1 /etc/systemd/system/multi-user.target.wants/lnet-*@${1}.service 2> /dev/null); do
+ systemctl stop ${i##*/} &> /dev/null
+ rm $i &> /dev/null
+ done
+}
+
+systemd_enable() {
+ systemd_disable_existing $1
+ ln -s $SYSTEMDUNITDIR/${2}@.service /etc/systemd/system/multi-user.target.wants/${2}@${1}.service
+ systemctl start ${2}@${1}.service &> /dev/null
+ # Set default gw if not already set
+ if [ -f /etc/config.d/gateway ] && systemctl -q is-enabled lnet-default-gateway.service ; then
+ GATEWAY=$(cat /etc/config.d/gateway)
+ CURRENT_GW=$(ip route show default | grep ^default | awk '{ print $3 }')
+ if [ -n $GATEWAY ] && [[ "$GATEWAY" != "$CURRENT_GW" ]]; then
+ systemctl start lnet-default-gateway.service
+ fi
+ fi
+}
+
+systemd_disable() {
+ systemctl stop ${2}@${1}.service &> /dev/null
+ rm /etc/systemd/system/multi-user.target.wants/${2}@${1}.service &> /dev/null
+}
+
+systemd_gw_template() {
+ cat <<EOF > /etc/systemd/system/lnet-default-gateway.service
+[Unit]
+Description=Network default gateway
+Wants=network.target
+After=network.target
+
+[Service]
+Type=oneshot
+RemainAfterExit=yes
+ExecStart=/usr/sbin/ip route add default via $(/usr/bin/cat /etc/config.d/gateway)
+ExecStop=/usr/sbin/ip route del default
+
+[Install]
+WantedBy=multi-user.target
+EOF
+}
+
+get_systemd_servicetype() {
+ local SERVICETYPE
+
+ if [ "$ADDRESS" = "dhcp" ]; then
+ SERVICETYPE="lnet-${DHCP_CLIENT}"
+ else
+ SERVICETYPE="lnet-static"
fi
+ echo $SERVICETYPE
}
main ()
{
unset PROMPT
+
while true; do
COUNTER=0
unset LIST
for DEVICE in `get_dev_list`; do
- if [ -L $CONFIG_DIR/$DEVICE ]; then
- continue
- fi
+ if [ -L $CONFIG_DIR/$DEVICE ]; then
+ continue
+ fi
STATUS=`get_dev_status $DEVICE`
INTERFACES[$COUNTER]=$DEVICE
if [ -z "$LIST" ]; then
@@ -182,6 +239,15 @@ function gateway_config() {
GATEWAY=$(cat /etc/config.d/gateway)
GATEWAY=`inputbox "$GATEWAY_PROMPT" "$GATEWAY"`
echo "$GATEWAY" > /etc/config.d/gateway
+ if [ -n $SYSTEMDUNITDIR ]; then
+ if [ -n "$GATEWAY" ]; then
+ systemd_gw_template
+ systemctl daemon-reload &> /dev/null
+ systemctl enable lnet-default-gateway.service
+ else
+ systemctl disable lnet-default-gateway.service
+ fi
+ fi
}
function ethernet_menu() {
@@ -203,7 +269,14 @@ function ethernet_menu() {
case $COMMAND in
C) ethernet_config $1;;
M) ethernet_manage_device $1;;
- D) if confirm "Are you sure you wish to delete $1?" "--defaultno"; then rm -f "$CONFIG_DIR/$1"; fi;;
+ D)
+ if confirm "Are you sure you wish to delete $1?" "--defaultno"; then
+ if [ -n $SYSTEMDUNITDIR ]; then
+ systemd_disable_existing ${1}
+ fi
+ rm -f "$CONFIG_DIR/$1"
+ fi
+ ;;
esac
}
@@ -255,7 +328,7 @@ function ethernet_manage_device() {
while true; do
STATUS=`get_dev_status $1`
- if [[ "$STATUS" == "[_UP_]" ]]; then
+ if [[ "$STATUS" == "[ UP ]" ]]; then
TOGGLE="Stop"
else
TOGGLE="Start"
@@ -277,11 +350,27 @@ function ethernet_manage_device() {
$DIALOG --infobox "$DHCP_TIMEOUT" 0 0
case $COMMAND in
- S) /etc/init.d/network `echo $TOGGLE | tr 'S' 's'` "$1" ;;
- R) /etc/init.d/network restart "$1" ;;
+ S)
+ # Assume systemd is running
+ if [ -n $SYSTEMDUNITDIR ]; then
+ SERVICETYPE=$(get_systemd_servicetype)
+ systemctl ${TOGGLE/S/s} ${SERVICETYPE}@${1}.service
+ else
+ /etc/init.d/network ${TOGGLE/S/s} "$1"
+ fi
+ ;;
+ R)
+ # Assume systemd is running
+ if [ -n $SYSTEMDUNITDIR ]; then
+ SERVICETYPE=$(get_systemd_servicetype)
+ systemctl restart ${SERVICETYPE}@${1}.service
+ else
+ /etc/init.d/network restart "$1"
+ fi
+ ;;
esac
- if [[ "$(/sbin/ifconfig | grep $1 | wc -l)" -ge "1" ]]; then
+ if [[ "$(ifconfig | grep $1 | wc -l)" -ge "1" ]]; then
T=1; else T=0
fi
@@ -299,11 +388,40 @@ unset WIRELESS DEVICE AUTO MODULE MODULE_OPTIONS ADDRESS MANAGER
unset NETMASK BROADCAST GATEWAY DHCP_CLIENT DHCP_OPTIONS
unset WIRELESS_KEY WIRELESS_RATE WIRELESS_MODE WIRELESS_ESSID
+if_template() {
+ cat > $CONFIG_DIR/$DEVICE << EOF
+#
+# configuration for "$DEVICE"
+# automatically generated by lnet - do not edit, run 'lnet' instead
+# -- `date`
+#
+AUTO="${AUTO:-Y}"
+MODULE="$MODULE"
+MODULE_OPTIONS="$MODULE_OPTIONS"
+
+MANAGER="${MANAGER:-manual}"
+
+WIRELESS="${WIRELESS:-N}"
+WIRELESS_KEY="$WIRELESS_KEY"
+WIRELESS_RATE="$WIRELESS_RATE"
+WIRELESS_MODE="$WIRELESS_MODE"
+WIRELESS_ESSID="$WIRELESS_ESSID"
+
+ADDRESS="$ADDRESS"
+NETMASK="$NETMASK"
+BROADCAST="$BROADCAST"
+IFCONF_OPTS="$IFCONF_OPTS"
+
+DHCP_CLIENT="${DHCP_CLIENT:-dhcpcd}"
+DHCP_OPTIONS="$DHCP_OPTIONS"
+EOF
+}
+
if [ -n "$1" ]; then
- . $CONFIG_DIR/$1
+ . $CONFIG_DIR/$1
fi
- DHCP_MODULE_MESSAGE="The DHCP client you have chosen is not installed. Before your device will work, you will need to install the following module: "
+DHCP_MODULE_MESSAGE="The DHCP client you have chosen is not installed. Before your device will work, you will need to install the following module: "
if [ -z $1 ]; then
while [ -z $DEVICE ]; do
@@ -316,6 +434,12 @@ if [ -z $1 ]; then
fi
done
DEVICE=`inputbox "For more then one device, use the menu for each of them, ie: eth0, eth1 etc.." "$TDEV"`
+
+ # Generate a file immediately with some sane defaults
+ AUTO="Y"
+ ADDRESS="dhcp"
+ if_template
+ . $CONFIG_DIR/$DEVICE
done
else
DEVICE=$1
@@ -329,9 +453,12 @@ while true ; do
--default-item "$DEFAULT" \
--menu "" 0 0 0 \
"A" "Automatically start? [${AUTO:-Y}]" \
- "L" "kernel module to Load [${MODULE:-}]" \
- "Z" "Use manager? [${MANAGER:-manual}]" \
- $(if [ "${MANAGER:-manual}" == "manual" ] ; then
+ $(if [ -z $SYSTEMDUNITDIR ]; then
+ echo "L"
+ echo "kernel module to Load [${MODULE:-}]"
+ echo "Z"
+ echo "Use manager? [${MANAGER:-manual}]"
+ if [ "${MANAGER:-manual}" == "manual" ] ; then
echo "W"
echo "Wireless device? [${WIRELESS:-N}]"
if [ "$WIRELESS" == "Y" ]; then
@@ -344,29 +471,39 @@ while true ; do
echo "E"
echo "Essid [${WIRELESS_ESSID:-default}]"
fi
+ fi
+ fi
echo "D"
echo "Dhcp enabled? [$(echo $ADDRESS | grep -qi dhcp && echo "Y" || echo "N")]"
- fi
if [ "$MANAGER" != "manual" ] || [ "$ADDRESS" == "dhcp" ] ; then
echo "C"
echo "Dhcp client [${DHCP_CLIENT:-dhcpcd}]"
echo "O"
- echo "Dhcp options [${DHCP_OPTIONS:--h \`hostname\`}]"
+ echo "Dhcp options [${DHCP_OPTIONS}]"
fi
if [ "$ADDRESS" != "dhcp" ] ; then
echo "I"
- echo "IP Address [${ADDRESS:-10.0.0.1}]"
+ echo "IP Address [${ADDRESS}]"
echo "N"
- echo "Netmask [${NETMASK:-255.255.255.0}]"
+ echo "Netmask [${NETMASK}]"
echo "B"
- echo "Broadcast [${BROADCAST:-10.0.0.255}]"
- echo "F"
- echo "Ifconfig options [${IFCONF_OPTS:-}]"
+ echo "Broadcast [${BROADCAST}]"
+ if [ -z $SYSTEMDUNITDIR ]; then
+ echo "F"
+ echo "Ifconfig options [${IFCONF_OPTS:-}]"
+ fi
fi
- )`
+
+ )`
if [ $? != 0 ]; then
- return
+ # Assume systemd is running if SYSTEMDUNITDIR variable is set
+ if [ -n $SYSTEMDUNITDIR ]; then
+ DHCP_TIMEOUT="This device uses DHCP. If no DHCP servers are available to give an IP address\nyou may need to wait for the device to timeout."
+ [ "$ADDRESS" = "dhcp" ] && $DIALOG --infobox "$DHCP_TIMEOUT" 0 0
+ [ "$AUTO" = "Y" ] && systemd_enable $DEVICE $(get_systemd_servicetype) || systemd_disable_existing $DEVICE
+ fi
+ return
fi
case $CHOICE in
@@ -420,18 +557,17 @@ while true ; do
--default-item "${DHCP_CLIENT:-dhcpcd}" \
--menu "" 0 0 0 \
"dhcpcd" "" \
- "dhclient" "" \
- "udhcpc" ""`
+ "dhclient" ""`
case $DHCP_CLIENT in
dhclient) if ! module_installed dhcp; then
msgbox "Warning" "$DHCP_MODULE_MESSAGE dhcp" 10
fi ;;
- udhcpc) if ! module_installed udhcp; then
- msgbox "Warning" "$DHCP_MODULE_MESSAGE udhcp" 10
+ dhcpcd) if ! module_installed dhcpcd; then
+ msgbox "Warning" "$DHCP_MODULE_MESSAGE dhcpcd" 10
fi ;;
esac
;;
- O) DHCP_OPTIONS=`inputbox "Enter extra options passed to $DHCP_CLIENT" "${DHCP_OPTIONS:--h \`hostname\`}"`
+ O) DHCP_OPTIONS=`inputbox "Enter extra options passed to $DHCP_CLIENT" "${DHCP_OPTIONS}"`
;;
I) ADDRESS=`inputbox "Enter IP address" "$ADDRESS"`
;;
@@ -445,42 +581,13 @@ while true ; do
# save the config
cp -p $CONFIG_DIR/$DEVICE /tmp/lnet.$DEVICE
- cat > $CONFIG_DIR/$DEVICE << EOF
-#
-# configuration for "$DEVICE"
-# automatically generated by lnet - do not edit, run 'lnet' instead
-# -- `date`
-#
-AUTO="$AUTO"
-MODULE="$MODULE"
-MODULE_OPTIONS="$MODULE_OPTIONS"
-
-MANAGER="$MANAGER"
-
-WIRELESS="$WIRELESS"
-WIRELESS_KEY="$WIRELESS_KEY"
-WIRELESS_RATE="$WIRELESS_RATE"
-WIRELESS_MODE="$WIRELESS_MODE"
-WIRELESS_ESSID="$WIRELESS_ESSID"
-
-ADDRESS="$ADDRESS"
-NETMASK="$NETMASK"
-BROADCAST="$BROADCAST"
-IFCONF_OPTS="$IFCONF_OPTS"
-
-DHCP_CLIENT="$DHCP_CLIENT"
-DHCP_OPTIONS="$DHCP_OPTIONS"
-
-ROUTE_1="$ROUTE_1"
-ROUTE_2="$ROUTE_2"
-ROUTE_3="$ROUTE_3"
-ROUTE_4="$ROUTE_4"
-EOF
+ if_template
done
}
. /etc/lunar/config
+. $BOOTSTRAP
root_check
@@ -493,4 +600,9 @@ Lunar Network Management Utility
trap catch_sig INT
trap ":" QUIT
+# Check if we have systemd and that it is running
+if module_installed systemd && [ -d /run/systemd ]; then
+ SYSTEMDUNITDIR=$(pkg-config systemd --variable=systemdsystemunitdir)
+fi
+
main

0 comments on commit 4ec3881

Please sign in to comment.