2

I am using a Yocto image based on the linux-mainline kernel. I have systemd on the embedded OS that I have created.

Aim

I have a UMTS dongle connected to the board which will use usb_modeswitch to recognise the dongle and wvdial to connect to the 3G insfrastructure.

Method

I wrote a simple bash script in /usr/umts.sh as follows

#!/bin/bash

sleep 1;
usb_modeswitch --default-vendor 12d1 --default-product 1446 -J

sleep 1;
/usr/bin/tmux new-session -d -s Cloud
/usr/bin/tmux set-option set-remain-on-exit on
/usr/bin/tmux new-window -d -n 'wvdial' -t Cloud:1 'sleep 1; /usr/bin/wvdialconf; /usr/bin/wvdial';

usb_modeswitch will configure the USB Dongle and the next part will create a tmux session and trigger wvdial within.

my systemd script looks like follows in /etc/systemd/system/enable-umts.service

GNU nano 2.2.5 File: /etc/systemd/system/enable-umts.service

[Unit]
Description=Enable UMTS Dongle for Cloud Connectivity

[Service]
Type=oneshot
ExecStart=/usr/umts.sh

[Install]
WantedBy=default.target

(I have given execution rights to the script using chmod +x /usr/umts.sh)

I reloaded the daemon systemctl daemon-reload and enabled the service systemctl enable enable-umts.service

and rebooted the board (NOTE: I have only root on board and no other user)

The dmesg infact triggers the usb_modeswitch from the script above and I see related messages

[  OK  ] Started Enable UMTS Dongle for Cloud Connectivity.
[   13.051247] scsi host2: usb-storage 1-1:1.5
[   13.067326] usb-storage 1-1:1.6: USB Mass Storage device detected
[   13.074645] scsi host3: usb-storage 1-1:1.6
[   13.158627] usbcore: registered new interface driver usbserial
[   13.165501] usbcore: registered new interface driver usbserial_generic
[   13.174754] usbserial: USB Serial support registered for generic
[   13.202356] usbcore: registered new interface driver option
[   13.208714] usbserial: USB Serial support registered for GSM modem (1-port)
[   13.216468] option 1-1:1.0: GSM modem (1-port) converter detected
[   13.229840] usb 1-1: GSM modem (1-port) converter now attached to ttyUSB0
[   13.238774] option 1-1:1.3: GSM modem (1-port) converter detected
[   13.248906] usb 1-1: GSM modem (1-port) converter now attached to ttyUSB1
[   13.256172] option 1-1:1.4: GSM modem (1-port) converter detected
[   13.264467] usb 1-1: GSM modem (1-port) converter now attached to ttyUSB2
[   14.069960] scsi 2:0:0:0: CD-ROM            HUAWEI   Mass Storage     2.31 PQ: 0 ANSI: 2
[   14.088684] scsi 3:0:0:0: Direct-Access     HUAWEI   TF CARD Storage       PQ: 0 ANSI: 2
[   14.127686] sd 3:0:0:0: [sda] Attached SCSI removable disk
GSM modem (1-port) converter detected
] usb 1-1: GSM modem (1-port) converter now attached to ttyUSB0
[   13.238774] option 1-1:1.3: GSM modem (1-port) converter detected
[   13.248906] usb 1-1: GSM modem (1-port) converter now attached to ttyUSB1
[   13.256172] option 1-1:1.4: GSM modem (1-port) coPassword

But upon login I try to list the sessions tmux ls and it states there are no sessions created.

The `script in fact does not fail and the service status is as follows:

● enable-umts.service - Enable UMTS Dongle for Cloud Connectivity
   Loaded: loaded (/etc/systemd/system/enable-umts.service; enabled; vendor preset: enabled)
   Active: inactive (dead) since Thu 2018-05-17 12:52:10 UTC; 4min 51s ago
  Process: 214 ExecStart=/usr/umts.sh (code=exited, status=0/SUCCESS)
 Main PID: 214 (code=exited, status=0/SUCCESS)

May 17 12:52:09 phyboard-mira-imx6-3 umts.sh[214]: Set up interface 0
May 17 12:52:09 phyboard-mira-imx6-3 umts.sh[214]: Use endpoint 0x01 for message sending ...
May 17 12:52:09 phyboard-mira-imx6-3 umts.sh[214]: Trying to send message 1 to endpoint 0x01 ...
May 17 12:52:09 phyboard-mira-imx6-3 umts.sh[214]:  OK, message successfully sent
May 17 12:52:09 phyboard-mira-imx6-3 umts.sh[214]: Reset response endpoint 0x81
May 17 12:52:09 phyboard-mira-imx6-3 umts.sh[214]: Reset message endpoint 0x01
May 17 12:52:09 phyboard-mira-imx6-3 umts.sh[214]:  Could not reset endpoint (probably harmless): -99
May 17 12:52:09 phyboard-mira-imx6-3 umts.sh[214]:  Device is gone, skip any further commands
May 17 12:52:09 phyboard-mira-imx6-3 umts.sh[214]: -> Run lsusb to note any changes. Bye!
May 17 12:52:10 phyboard-mira-imx6-3 systemd[1]: Started Enable UMTS Dongle for Cloud Connectivity.

If execute the script /usr/umts.sh as a standalone script then in fact it does everything it is supposed to do (open a new tmux session and triggers wvdial)

What is wrong here? I tried adding more sleep time but that isn't working either. Sadly there is no rc.local or cron available for the yocto image I am working on.

2
  • You can try using tmux -v .... It will create 2 files tmux-* in the current directory of the command. This log is very verbose and not very comprehensible but may give a clue as to why it fails, or even if it ran.
    – meuh
    May 17 '18 at 14:11
  • 1
    I added RemainAfterExit=true in my systemd script and now it works.
    – Shan-Desai
    May 17 '18 at 14:32
2

I added RemainAfterExit=yes|true in my systemd Script as follows:

[Unit]
Description=Enable UMTS Dongle for Cloud Connectivity

[Service]
Type=oneshot
ExecStart=/usr/umts.sh
RemainAfterExit=true
[Install]
WantedBy=default.target

Added full paths to the umts.sh script as follows:

#!/bin/bash

    sleep 1;
    /usr/bin/tmux new-session -d -s Cloud
    /usr/bin/tmux set-option set-remain-on-exit on
    /usr/bin/tmux new-window -d -n 'usb_modeswitch' -t Cloud:2 '/usr/sbin/usb_modeswitch --default-vendor 12d1 --default-product 1446 -J';

    /usr/bin/tmux new-window -d -n 'wvdial' -t Cloud:1 'sleep 10; /usr/bin/wvdialconf; /usr/bin/wvdial';

Reloaded the daemon

systemctl daemon-reload

and rebooted the board. and Found the tmux sessions created and running perfectly

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.