[Lunar-commits] <lunar-tools> Added systemd support for static and dhcp configruations
Stefan Wold
ratler at lunar-linux.org
Tue Jul 31 11:37:39 CEST 2012
commit 1edad584dde7c3fd9102ec899f862ba4d160d60f
Author: Stefan Wold <ratler at lunar-linux.org>
Date: Mon, 25 Jun 2012 21:31:33 -0700
URL: https://github.com/lunar-linux/lunar-tools/commit/1edad584dde7c3fd9102ec899f862ba4d160d60f
Added systemd support for static and dhcp configruations
TODO for systemd:
- Add default gateway support
- Add wireless support
- Add route support per device
---
lnet/lnet +96/-4
1 files changed, 96 insertions (+), 4 deletions (-)
--- a/lnet/lnet
+++ b/lnet/lnet
@@ -65,6 +65,28 @@ get_dev_status() {
fi
}
+function systemd_reload() {
+ systemctl daemon-reload > /dev/null 2>&1
+}
+
+function systemd_enable() {
+ systemctl -q enable $1
+}
+
+function systemd_disable() {
+ systemctl -q disable $1
+}
+
+function systemd_reload_enable() {
+ systemd_reload
+ systemd_enable $1
+}
+
+function systemd_reload_disable() {
+ systemd_reload
+ systemd_disable $1
+}
+
main ()
{
unset PROMPT
@@ -205,7 +227,17 @@ 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
+ rm -f "$CONFIG_DIR/$1"
+ if [ -d /run/systemd ]; then
+ local SYSTEMDUNITDIR=$(pkg-config systemd --variable=systemdsystemunitdir)
+ systemd_disable ${1}.service
+ rm -f $SYSTEMDUNITDIR/${1}.service
+ systemd_reload
+ fi
+ fi
+ ;;
esac
}
@@ -279,8 +311,28 @@ 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 /run/systemd exists
+ if [ -d /run/systemd ]; then
+ local SYSTEMDUNITDIR=$(pkg-config systemd --variable=systemdsystemunitdir)
+ if [ -f $SYSTEMDUNITDIR/${1}.service ]; then
+ systemctl ${TOGGLE/S/s} ${1}.service
+ fi
+ else
+ /etc/init.d/network ${TOGGLE/S/s} "$1"
+ fi
+ ;;
+ R)
+ # Assume systemd is running if /run/systemd exists
+ if [ -d /run/systemd ]; then
+ local SYSTEMDUNITDIR=$(pkg-config systemd --variable=systemdsystemunitdir)
+ if [ -f $SYSTEMDUNITDIR/${1}.service ]; then
+ systemctl restart ${1}.service
+ fi
+ else
+ /etc/init.d/network restart "$1"
+ fi
+ ;;
esac
if [[ "$(/sbin/ifconfig | grep $1 | wc -l)" -ge "1" ]]; then
@@ -302,7 +354,7 @@ unset NETMASK BROADCAST GATEWAY DHCP_CLIENT DHCP_OPTIONS
unset WIRELESS_KEY WIRELESS_RATE WIRELESS_MODE WIRELESS_ESSID
if_template() {
- cat > $CONFIG_DIR/$DEVICE << EOF
+ cat > $CONFIG_DIR/$DEVICE << EOF
#
# configuration for "$DEVICE"
# automatically generated by lnet - do not edit, run 'lnet' instead
@@ -333,6 +385,46 @@ ROUTE_2="$ROUTE_2"
ROUTE_3="$ROUTE_3"
ROUTE_4="$ROUTE_4"
EOF
+
+ # Assume systemd is running if /run/systemd exists
+ # Create ethX.service file
+ if [ -d /run/systemd ]; then
+ local SYSTEMDUNITDIR=$(pkg-config systemd --variable=systemdsystemunitdir)
+ if [ "$ADDRESS" = "dhcp" ]; then
+ cat > $SYSTEMDUNITDIR/${DEVICE}.service <<EOF
+[Unit]
+Description=DHCPCD client daemon $DEVICE
+Wants=network.target
+Before=network.target
+
+[Service]
+ExecStart=/usr/sbin/dhcpcd -q --nobackground $DEVICE
+
+[Install]
+WantedBy=multi-user.target
+EOF
+ else
+ cat > $SYSTEMDUNITDIR/${DEVICE}.service <<EOF
+[Unit]
+Description=Network connecitivity $DEVICE
+Wants=network.target
+Before=network.target
+
+[Service]
+Type=oneshot
+RemainAfterExit=yes
+EnvironmentFile=/etc/config.d/network/${DEVICE}
+ExecStart=/usr/sbin/ip link set dev ${DEVICE} up
+ExecStart=/usr/sbin/ip addr add \${ADDRESS}/\${NETMASK} broadcast \${BROADCAST} dev ${DEVICE}
+ExecStop=/usr/sbin/ip addr flush dev ${DEVICE}
+ExecStop=/usr/sbin/ip link set dev ${DEVICE} down
+
+[Install]
+WantedBy=multi-user.target
+EOF
+ fi
+ [ "$AUTO" = "Y" ] && systemd_reload_enable ${DEVICE}.service || systemd_reload_disable ${DEVICE}.service
+ fi
}
if [ -n "$1" ]; then
More information about the Lunar-commits
mailing list