Run Dyalog on Raspberry PI Boot

For Raspberry Pi specific issues .. more general issues will appear in UNIX and Linux

Run Dyalog on Raspberry PI Boot

Postby tomgarwin on Tue Jul 25, 2017 5:44 pm

Has anyone succeeded in running Dyalog (with a specific startup workspace) when the Raspberry PI Boots up? I've tried all the recommended methods (Systemd, Cron, rc.local, ... with no success. It seems the Dyalog script generates a Bash error when called in these ways but not when called directly from a terminal. I also tried running it from LXterminal in a startup script and that didn't work either. I am not fluent in Linux so there are many ways I could have gone wrong
tomgarwin
 
Posts: 23
Joined: Sun Jul 23, 2017 11:37 am

Re: Run Dyalog on Raspberry PI Boot

Postby Brian|Dyalog on Wed Jul 26, 2017 2:50 pm

Hi Tom,

At the 2016 Vassar Hackathon, we brought 5 Raspberry Pi's and a router so that the students could access Dyalog APL via RIDE. We essentially ran our own timesharing service. :)

Each Pi would start 3 RIDEable APL sessions, so we could have up to 15 students playing with APL at a time. I've grabbed the code and tweaked it a bit here to load the sudoku workspace. Hopefully it will give you a starting point to work with...

First, you'll need to have the Linux screen utility installed (Google "linux screen raspberry pi" if you aren't familiar with screen).

There may be better ways to accomplish this, but this is what worked for our Hackathon purposes.

/etc/rc.local
Note, I'm only starting a single RIDEable APL
Code: Select all
#!/bin/sh -e                                                         
#                                                                   
# rc.local                                                           
#                                                                   
# This script is executed at the end of each multiuser runlevel.     
# Make sure that the script will "exit 0" on success or any other   
# value on error.                                                   
#                                                                   
# In order to enable or disable this script just change the execution
# bits.                                                             
#                                                                   
# By default this script does nothing.                               
                                                                     
sudo -u pi /home/pi/startRIDEs 1                                     
                                                                     
# Print the IP address                                               
_IP=$(hostname -I) || true                                           
if [ "$_IP" ]; then                                                 
  printf "My IP address is %s\n" "$_IP"                             
fi                                                                   
                                                                     
exit 0


/home/pi/startRIDEs
Note the call to screen
Code: Select all
#!/bin/bash                                                 
# Start $1 Dyalog sessions listening on ports beginning at $2
if [ "$1" = "" ]; then                                       
   CTR=1                                                       
else                                                         
   CTR=$1                                                     
fi                                                           
if [ "$2" = "" ]; then                                       
   PORT=4502                                                   
else                                                         
   PORT=$2                                                     
fi                                                           
while [ $CTR -gt 0 ]; do                                     
   screen -dm /home/pi/startDyalog $PORT                       
   let CTR-=1                                                 
   let PORT+=1                                                 
done       


/home/pi/startDyalog
All I did was add the workspace name (sudoku) after dyalog
Code: Select all
#!/bin/bash                                         
# Argument is port number for RIDE to listen on >1025
if [ "$1" != "" ]; then                             
   cd /home/pi                                         
   RIDE_INIT=serve::$1 dyalog sudoku                   
else                                                 
   dyalog sudoku                                       
fi   


I hope this helps!
User avatar
Brian|Dyalog
 
Posts: 116
Joined: Thu Nov 26, 2009 4:02 pm
Location: West Henrietta, NY

Re: Run Dyalog on Raspberry PI Boot

Postby ray on Wed Jul 26, 2017 8:10 pm

Hi Tom

If you want the RIDE interface see Brian's reply.

I am running a Dyalog controlled robot on a old raspberry pi (model 1).

Its Headless (no screen) and on power/boot up starts up APL.

Within /etc/rc.local (which is run as part of the boot up process, that Brian mentions) just before the last line (which should be "exit 0")
I call my script which then runs Dyalog APL

My script is:
Code: Select all
#!/bin/bash
# Start Audio menu from dyalog
say "Starting MENU"
sudo TERM=xterm dyalog /home/pi/menu.dws
say "Menu ended"


I use "sudo" because I am accessing the RPi's GPIO pins that need root access.

"say" is a text to speech script, that read out the text through a loudspeaker.
and the menu.dws is a workspace that reads out menus that is implemented using ⎕SM.

Note that this is NOT using RIDE nor the RPi's GUI interface.

This if great for running APPS written in APL, but does NOT provide an APL development environment.

Ray
Ray Cannon
Please excuse any smelling pisstakes.
User avatar
ray
 
Posts: 218
Joined: Wed Feb 24, 2010 12:24 am
Location: Blackwater, Camberley. UK

Re: Run Dyalog on Raspberry PI Boot

Postby aplpete on Thu Jul 27, 2017 12:09 pm

I have a simple webcam application written using miserver running on a pi2 with Wheezy and Dyalog 14.0. The pi is mounted on the top of a chimney in Greece and is subject to frequent power cuts. Thanks to the advice from Brian and Ray, it now restarts automatically when the power comes back on. My script "/home/pi/webcamboot" is called from /etc/rc.local as follows: (The sudo in rc.local is essential to avoid being prompted for a password). I don't currently use RIDE, but I can connect to the session by typing "screen -r webcam".

~/webcamboot
============

#!/bin/sh
/usr/bin/dyalog ~/miserver/mserver.dws

/etc/rc.local
=============

#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.

# Print the IP address
_IP=$(hostname -I) || true
if [ "$_IP" ]; then
printf "My IP address is %s\n" "$_IP"
fi

sudo su - pi -c "screen -dm -S webcam ~/webcamboot"

exit 0
aplpete
 
Posts: 1
Joined: Tue Dec 14, 2010 11:50 am

Re: Run Dyalog on Raspberry PI Boot

Postby tomgarwin on Thu Aug 03, 2017 12:03 am

THanks for all the help. Unfortunately I couldnt make any of this work. Is it possible that there is something in the Dyalog script distributed with version 16.0 that works when executed from a terminal but doesnt when run on startup? I am running a PI 3 with debian jessie and I have seen lots of talk about rc.local not working so I tried systemD --

I have a modified version of this script that starts listening to RIDE but I figured I would start with the unmodified script so I didnt introduce new problems.

I get the following error result - APL seems to start and then terminate (?)

pi@rpi3btg1:~ $ sudo systemctl status -l tgsplunit.service
● tgsplunit.service - For APL Dyalog Ride Start up on Boot
Loaded: loaded (/lib/systemd/system/tgsplunit.service; enabled)
Active: failed (Result: exit-code) since Wed 2017-08-02 17:47:49 MDT; 51s ago
Process: 803 ExecStart=/usr/bin/dyalog (code=exited, status=2)
Main PID: 803 (code=exited, status=2)

Aug 02 17:47:49 rpi3btg1 dyalog[803]: Dyalog APL/S Version 16.0.30270 Unicode
Aug 02 17:47:49 rpi3btg1 dyalog[803]: For ARM11
Aug 02 17:47:49 rpi3btg1 dyalog[803]: Created: Jun 28 2017 at 11:09:50
Aug 02 17:47:49 rpi3btg1 dyalog[803]: Copyright (c) Dyalog Limited 1982-2017
Aug 02 17:47:49 rpi3btg1 dyalog[803]: EOF INTERRUPT
Aug 02 17:47:49 rpi3btg1 systemd[1]: Child 803 belongs to tgsplunit.service
Aug 02 17:47:49 rpi3btg1 systemd[1]: tgsplunit.service: main process exited, code=exited, status=2/INVALIDARGUMENT
Aug 02 17:47:49 rpi3btg1 systemd[1]: tgsplunit.service changed running -> failed
Aug 02 17:47:49 rpi3btg1 systemd[1]: Unit tgsplunit.service entered failed state.
Aug 02 17:47:49 rpi3btg1 systemd[1]: tgsplunit.service: cgroup is empty
pi@rpi3btg1:~ $

THis is the Ünit (service) file:

Unit]
Description=For APL Dyalog Ride Start up on Boot
After=multi-user.target

[Service]
Type=idle
ExecStart=/usr/bin/dyalog

[Install]
WantedBy=multi-user.target
tomgarwin
 
Posts: 23
Joined: Sun Jul 23, 2017 11:37 am

Re: Run Dyalog on Raspberry PI Boot

Postby Jason|Dyalog on Thu Aug 10, 2017 1:09 pm

*Updated without sockets*

Hi Tom.

I've had a bit of a play with this today, First of all the reason you're seeing EOF INTERRUPT is because the APL has no input and therefor doesn't know what to do. What you need to do is redirect input from a socket, unfortunately you can't do this within systemd using StandardInput=socket, as the socket also needs to have a stream to it (of nulls). or you can redirect with 0<&- which I also haven't got working in systemd currently

This is all stuff that we're hoping will be better for version 17.0, the current issue is due to the way we set ride up which currently needs a session.

My current solution to this was to create a file: /usr/local/bin/dyalogstartup
*Updated without sockets and added -q so the APL doesn't exit on error*
Code: Select all
#!/bin/bash

echo "Launching dyalog"

/opt/mdyalog/16.0/64/unicode/mapl +s -ride -q 0<&-



Make sure you set the file to be executable: chmod +x /usr/local/bin/dyalogstartup

You also want to make sure that you're not running Dyalog as root, the only time you should run Dyalog as root is when you intend on binding on a TCP port lower than 1024 on Linux/Unix, and then us 4001⌶ to change to a user once you've bound to the TCP port.

Here's my /lib/systemd/system/dyalog.service file

Code: Select all
[Unit]
Description=Dyalog APL Ride Start up
After=multi-user.target

[Service]
Type=simple
User=jason
Group=dyalog
WorkingDirectory=~
StandardError=null
ExecStart=/usr/local/bin/dyalogstartup

[Install]
WantedBy=multi-user.target


Make sure you set the User to your username (or pi if you're using the pi user) and the same for your group.
The working directory will be the users home directory, You can change this to any directory you wish, but make sure you have permissions to read/write.
Jason|Dyalog
 
Posts: 22
Joined: Tue Sep 09, 2008 2:42 pm

Re: Run Dyalog on Raspberry PI Boot

Postby tomgarwin on Thu Aug 10, 2017 5:02 pm

Hi Jason,

Thanks very much for this help. I am sure it will be useful to others as well.

Tom
tomgarwin
 
Posts: 23
Joined: Sun Jul 23, 2017 11:37 am

Re: Run Dyalog on Raspberry PI Boot

Postby tomgarwin on Tue Jul 24, 2018 4:24 am

I copied the systemd approach and the desired workspace now runs on boot-up in version 16.0, which is the main thing I wanted. But I haven't figured out how to attach (via ride) to the session that is already running. Given that there seem to be changes in RIDE in version 17.0 it seems to make sense to wait to try with the new version.

Thanks again

Tom
tomgarwin
 
Posts: 23
Joined: Sun Jul 23, 2017 11:37 am

Re: Run Dyalog on Raspberry PI Boot

Postby tomgarwin on Tue Jul 24, 2018 6:27 pm

I now have RIDE 4.0 connected just fine to the session previously running on the rPI.
tomgarwin
 
Posts: 23
Joined: Sun Jul 23, 2017 11:37 am


Return to Raspberry Pi

Who is online

Users browsing this forum: No registered users and 1 guest