On Mon, Jul 03, 2023 at 04:03:47PM +0200, Andreas Henriksson wrote:
Control: forcemerge -1 1039413
Control: severity -1 important
Control: retitle -1 vtun: please provide vtun@.service and mask init script

Hello,

I'm attaching a patch for the vtun debian package that should hopefully
be a good start in migrating to native systemd units.
The patch is COMPLETELY UNTESTED as I'm not myself a user of vtun.
Please make sure to set FIRST_SYSTEMD_SERVICE_VERSION to the correct
debian package version including these changes.

The attached patch adds a vtun@.service as the init script seems to have
used a home-brew template units style.
The /etc/default/vtun CLIENT$i_* variables are broken up into separate
vtun@.service instances, eg CLIENT1_NAME, CLIENT1_HOST, CLIENT1_ARGS
goes to vtun@CLIENT1.service override as NAME, HOST and OPTIONS.
This is done as a one-time migration....
(This also lifts the restrictions of having 0-9 instances.)

You most likely also want to make sure vtun.service (without the @)
is a symlink to /dev/null, to mask the init script.


See also:

https://src.fedoraproject.org/rpms/vtun/tree/81e15b3a03b89bffe0e6076a235720d40f343292

You might also want to provide the socket unit....

Regards,
Andreas Henriksson

diff '--color=auto' -uriNp vtun-3.0.4/debian/postinst 
vtun-3.0.4.systemd/debian/postinst
--- vtun-3.0.4/debian/postinst  2019-11-11 01:17:37.000000000 +0100
+++ vtun-3.0.4.systemd/debian/postinst  2023-07-03 15:47:08.717223223 +0200
@@ -46,6 +46,36 @@ case "$1" in
    ;;
esac

+# migrate old init.d style settings to systemd
+FIRST_SYSTEMD_SERVICE_VERSION="3.0.4-2.1"
+if [ "$1" = "configure" ] && dpkg --compare-versions "$2" lt-nl 
"$FIRST_SYSTEMD_SERVICE_VERSION~" ; then
+(
+    echo "Checking if we need to migrate /etc/default/vtun settings to 
'vtun@.service'."
+    if [ -e /etc/default/vtun ]; then
+        . /etc/default/vtun
+    fi
+
+    for i in 0 1 2 3 4 5 6 7 8 9; do
+            eval name=\$CLIENT${i}_NAME
+            eval host=\$CLIENT${i}_HOST
+            eval args=\$CLIENT${i}_ARGS
+            if [ -n "$name" ] && [ -n "$host" ]; then
+                echo "One-time migration of vtun CLIENT$i settings to 
vtun@CLIENT$i.service"
+                mkdir -p "/etc/systemd/system/vtun@CLIENT$i.service.d/"
+                echo "[Service]" >> 
"/etc/systemd/system/vtun@CLIENT$i.service.d/override.conf"
+                echo "Environment=\"NAME=$name\"" >> 
"/etc/systemd/system/vtun@CLIENT$i.service.d/override.conf"
+                echo "Environment=\"HOST=$host\"" >> 
"/etc/systemd/system/vtun@CLIENT$i.service.d/override.conf"
+                echo "Environment=\"OPTIONS=$args\"" >> 
"/etc/systemd/system/vtun@CLIENT$i.service.d/override.conf"
+                if [ -n "${RUN_SERVER:-}" ] && [ "${RUN_SERVER:-}" != "no" ]; 
then
+                    deb-systemd-helper enable "vtun@CLIENT$i"
+                fi
+            fi
+
+    done
+)
+fi
+
+
# dh_installdeb will replace this with shell code automatically
# generated by other debhelper scripts.

diff '--color=auto' -uriNp vtun-3.0.4/debian/vtun@.service 
vtun-3.0.4.systemd/debian/vtun@.service
--- vtun-3.0.4/debian/vtun@.service     1970-01-01 01:00:00.000000000 +0100
+++ vtun-3.0.4.systemd/debian/vtun@.service     2023-07-03 15:23:25.513183684 
+0200
@@ -0,0 +1,12 @@
+[Unit]
+Description=Virtual Tunnels over TCP/IP networks
+After=network.target
+
+[Service]
+ExecStart=/usr/sbin/vtund -n $OPTIONS $NAME $HOST
+# Reload should be synchronous, but signals are not...
+ExecReload=/usr/bin/kill -HUP $MAINPID
+Restart=on-failure
+
+[Install]
+WantedBy=multi-user.target


Uhm, it seems to me quite irritual using a template unit file without a 
template variable. Which reflects
the quite strange use of /etc/default/vtun with multiple indexed vars,
instead of multiple configuration files such as:

/etc/vtun.d/config?.vars (or even under /etc/vtun if you prefer so)

and of course you can override the env variables by using an /etc/vtun.d/%i.vars
where it makes sense in the template file. I think this would be the right 
moment to convert the
insane limited number of env var sets in /etc/default/vtun into multiple 
ordinary configuration
files and using something like that.

EnvironmentFile=-/etc/vtun.d/%i.vars

would override name, host and args variables.

I'm missing something?


--
Francesco P. Lovergine

Reply via email to