socket-uart: add runtime configuration through um-service-cfg

All serial based services gets their network configuration through
/etc/user-module/network.conf file
Introduced systemd target user-module

BugzID: 56443

Signed-off-by: Ramon Moesching <ramon.moesching@netmodule.com>
This commit is contained in:
Ramon Moesching 2019-04-05 16:03:14 +02:00
parent f46f7a1dca
commit 82bbc341d7
7 changed files with 29 additions and 52 deletions

View File

@ -1,25 +1,19 @@
#!/bin/sh #!/bin/sh
if [ -z $USER_MODULE_ipv4_addr ]; then
ping $SOCAT_SOCKET_KLINE_IP -w 3 -c 1 echo Start script by systemd service or set variables
else
if [ $? -eq 0 ]
then
if [ -x "$(command -v socat)" ]; then if [ -x "$(command -v socat)" ]; then
echo "start listening socket-uart services with server IP $SOCAT_SOCKET_KLINE_IP on port $SOCAT_SOCKET_KLINE_PORT" echo "start listening socket-uart services with server IP $USER_MODULE_ipv4_addr on port $USER_MODULE_kline_port"
cmd='socat -s pty,link=/dev/ttyUM1,raw,echo=0,b19200 tcp:$SOCAT_SOCKET_KLINE_IP:$SOCAT_SOCKET_KLINE_PORT' cmd='socat -s pty,link=/dev/ttyUM1,raw,echo=0,b19200 tcp:$USER_MODULE_ipv4_addr:$USER_MODULE_kline_port'
if [[ -n $SOCAT_SOCKET_KLINE_MSS ]]; then if [[ -n $SOCAT_SOCKET_KLINE_MSS ]]; then
eval $cmd,mss=$SOCAT_SOCKET_KLINE_MSS eval $cmd,mss=$SOCAT_SOCKET_KLINE_MSS
else else
eval $cmd eval $cmd
fi fi
else else
echo "socat command not available on your target or environment" echo "socat command not available on your target or environment"
# return 1 so that systemd knows the service failed to start
exit 1
fi fi
fi fi
exit 1 exit 1

View File

@ -1,25 +1,18 @@
#!/bin/sh #!/bin/sh
if [ -z $USER_MODULE_ipv4_addr ]; then
ping $SOCAT_SOCKET_LIN_IP -w 3 -c 1 echo Start script by systemd service or set variables
else
if [ $? -eq 0 ]
then
if [ -x "$(command -v socat)" ]; then if [ -x "$(command -v socat)" ]; then
echo "start listening socket-uart services with server IP $SOCAT_SOCKET_LIN_IP on port $SOCAT_SOCKET_LIN_PORT" echo "start listening socket-uart services with server IP $USER_MODULE_ipv4_addr on port $USER_MODULE_lin_port"
cmd='socat -s pty,link=/dev/ttyUM2,raw,echo=0 tcp:$SOCAT_SOCKET_LIN_IP:$SOCAT_SOCKET_LIN_PORT' cmd='socat -s pty,link=/dev/ttyUM2,raw,echo=0 tcp:$USER_MODULE_ipv4_addr:$USER_MODULE_lin_port'
if [[ -n $SOCAT_SOCKET_LIN_MSS ]]; then if [[ -n $SOCAT_SOCKET_LIN_MSS ]]; then
eval $cmd,mss=$SOCAT_SOCKET_LIN_MSS eval $cmd,mss=$SOCAT_SOCKET_LIN_MSS
else else
eval $cmd eval $cmd
fi fi
else else
echo "socat command not available on your target or environment" echo "socat command not available on your target or environment"
# return 1 so that systemd knows the service failed to start
exit 1
fi fi
fi fi
exit 1 exit 1

View File

@ -1,25 +1,19 @@
#!/bin/sh #!/bin/sh
if [ -z $USER_MODULE_ipv4_addr ]; then
ping $SOCAT_SOCKET_UART_IP -w 3 -c 1 echo Start script by systemd service or set variables
else
if [ $? -eq 0 ]
then
if [ -x "$(command -v socat)" ]; then if [ -x "$(command -v socat)" ]; then
echo "start listening socket-uart services with server IP $SOCAT_SOCKET_UART_IP on port $SOCAT_SOCKET_UART_PORT" echo "start listening socket-uart services with server IP $USER_MODULE_ipv4_addr on port $USER_MODULE_uart_port"
cmd='socat -s pty,link=/dev/ttyUM0,raw,echo=0,b115200 tcp:$SOCAT_SOCKET_UART_IP:$SOCAT_SOCKET_UART_PORT' cmd='socat -s pty,link=/dev/ttyUM0,raw,echo=0,b115200 tcp:$USER_MODULE_ipv4_addr:$USER_MODULE_uart_port'
if [[ -n $SOCAT_SOCKET_UART_MSS ]]; then if [[ -n $SOCAT_SOCKET_UART_MSS ]]; then
eval $cmd,mss=$SOCAT_SOCKET_UART_MSS eval $cmd,mss=$SOCAT_SOCKET_UART_MSS
else else
eval $cmd eval $cmd
fi fi
else else
echo "socat command not available on your target or environment" echo "socat command not available on your target or environment"
# return 1 so that systemd knows the service failed to start
exit 1
fi fi
fi fi
exit 1 exit 1

View File

@ -1,5 +1,7 @@
[Unit] [Unit]
Description=Bind kline socket with pseudo tty based on socat Description=Bind kline socket with pseudo tty based on socat
Requires=um-service-config.service user-module.target
After=um-service-config.service user-module.target
[Service] [Service]
Type=simple Type=simple
@ -7,15 +9,12 @@ ExecStart=/usr/bin/socat-socket-kline
PIDFile=/var/run/socket-kline.pid PIDFile=/var/run/socket-kline.pid
Environment=SOCAT_SOCKET_KLINE_IP='192.168.1.64' SOCAT_SOCKET_KLINE_PORT='2202' SOCAT_SOCKET_KLINE_MSS='' EnvironmentFile=/etc/user-module/network.conf
ExecReload=/bin/kill -HUP $MAINPID ExecReload=/bin/kill -HUP $MAINPID
Restart=on-failure Restart=on-failure
RestartSec=10 RestartSec=10
[Unit]
Wants=network-online.target
After=network-online.target
[Install] [Install]
WantedBy=multi-user.target WantedBy=user-module.target

View File

@ -1,5 +1,7 @@
[Unit] [Unit]
Description=Bind lin socket with pseudo tty based on socat Description=Bind lin socket with pseudo tty based on socat
Requires=um-service-config.service user-module.target
After=um-service-config.service user-module.target
[Service] [Service]
Type=simple Type=simple
@ -7,15 +9,11 @@ ExecStart=/usr/bin/socat-socket-lin
PIDFile=/var/run/socket-lin.pid PIDFile=/var/run/socket-lin.pid
Environment=SOCAT_SOCKET_LIN_IP='192.168.1.64' SOCAT_SOCKET_LIN_PORT='2200' SOCAT_SOCKET_LIN_MSS='' EnvironmentFile=/etc/user-module/network.conf
ExecReload=/bin/kill -HUP $MAINPID ExecReload=/bin/kill -HUP $MAINPID
Restart=on-failure Restart=on-failure
RestartSec=10 RestartSec=10
[Unit]
Wants=network-online.target
After=network-online.target
[Install] [Install]
WantedBy=multi-user.target WantedBy=user-module.target

View File

@ -1,5 +1,8 @@
[Unit] [Unit]
Description=Bind uart socket with pseudo tty based on socat Description=Bind uart socket with pseudo tty based on socat
Requires=um-service-config.service user-module.target
After=um-service-config.service user-module.target
[Service] [Service]
Type=simple Type=simple
@ -7,15 +10,11 @@ ExecStart=/usr/bin/socat-socket-uart
PIDFile=/var/run/socket-uart.pid PIDFile=/var/run/socket-uart.pid
Environment=SOCAT_SOCKET_UART_IP='192.168.1.64' SOCAT_SOCKET_UART_PORT='2204' SOCAT_SOCKET_UART_MSS='' EnvironmentFile=/etc/user-module/network.conf
ExecReload=/bin/kill -HUP $MAINPID ExecReload=/bin/kill -HUP $MAINPID
Restart=on-failure Restart=on-failure
RestartSec=10 RestartSec=10
[Unit]
Wants=network-online.target
After=network-online.target
[Install] [Install]
WantedBy=multi-user.target WantedBy=user-module.target

View File

@ -15,7 +15,7 @@ SRC_URI = " \
S = "${WORKDIR}" S = "${WORKDIR}"
RDEPENDS_${PN} = "socat" RDEPENDS_${PN} = "socat um-service-cfg"
SYSTEMD_SERVICE_${PN} = " \ SYSTEMD_SERVICE_${PN} = " \