Start node.js app on boot up? Similar to UDOO Web Control Panel.

Discussion in 'UDOO QUAD' started by rswamy, Nov 3, 2016.

  1. rswamy

    rswamy New Member

    Joined:
    Jul 29, 2016
    Messages:
    15
    Likes Received:
    6
    Hi,

    I have my own node.js app that I want to start on boot up. This is kind of like how the UDOO docs are available on the UDOO when it boots up, and are accessed through localhost:3000. I basically want to do the same thing, and also start a chromium instance at the URL localhost:3000.

    This is what I have tried so far:
    1. Created start up script at /usr/bin/scriptname.sh
    2. Made it executable with chmod, tested it by running it from terminal, it works

    I believe the next steps are to first add a service in /lib/systemd/system/scriptname.service
    Then create a symbolic link
    cd /etc/systemd/system/
    ln -s /lib/systemd/system/scriptname.service scriptname.service​

    I did all these steps but it's not working. Is this the same way the UDOO team did it?
     
  2. rswamy

    rswamy New Member

    Joined:
    Jul 29, 2016
    Messages:
    15
    Likes Received:
    6
    Ok so here's what I've learned so far.

    Ubuntu (including Udoobuntu) comes with upstart, a program that handles graceful starting of tasks at boot up and stopping tasks at shut down. To start a program on boot up, you need to create an upstart job. First, create a config file in /etc/init as <yourjob>.conf, which describes a job called <yourjob>. This config file is a template for a "service."

    in the terminal, man 5 init was a very helpful read.

    Here's my super basic service:

    description "Test service job"
    author "Ramya"

    env USER=root
    env PATH=/sbin:/bin:/usr/bin:/usr/sbin

    start on local-filesystems
    stop on [06]

    respawn

    script
    echo Test Job ran at `date` >> /var/log/testjob.log
    cd /opt/testjob/
    exec npm start
    exec chromium-browser --kiosk 'http://localhost:3000'
    end script

    If I go to localhost:3000 by manually opening a browser, after the UDOO starts up, my app is there and running.
    But chromium does not start up automatically. Any ideas?
     
  3. rswamy

    rswamy New Member

    Joined:
    Jul 29, 2016
    Messages:
    15
    Likes Received:
    6
    So I created a separate shell script to open up google chrome.
    I put it in /opt and called it launchHMI.sh. Contents:
    chromium-browser --kiosk 'http://localhost:3000'
    Then back in the upstart job definition, I added these line before the end script tag:
    cd /opt
    exec bash -c './launchHMI.sh'


    But it's still not working...

    -- edit1 (just learned how to use this button..)
    http://askubuntu.com/questions/507496/how-to-start-gui-application-with-upstart
    So basically upstart starts before the GUI loads, so that's why chrome wasn't loading.
    I removed the shell script and lines in the .conf job definition that were used to load the shell script.

    -- edit2
    after a lot of reading...
    http://askubuntu.com/questions/48321/how-do-i-start-applications-automatically-on-login
    I couldn't find the startup applications menu anywhere on the udoobuntu, so I had to install gnome-terminal, and gnome-session-properties from the command line. Gnome session properties is the actual startup application manager.
    sudo apt-get install gnome-terminal
    sudo apt-get install gnome-session-properties

    I'm not sure if gnome-terminal is even necessary but now I don't want to uninstall it..hah.
    I started up gnome-session-properties using the command

    gnome-session-properties
    then clicked ADD to add a new startup program. The command I used was
    chromium-browser --kiosk http://localhost:3000
    and I rebooted. it worked!
     
    Last edited: Nov 4, 2016
    Andrea Rovai and waltervl like this.
  4. waltervl

    waltervl UDOOer

    Joined:
    Dec 12, 2015
    Messages:
    2,314
    Likes Received:
    580
    Thank you for sharing this!
     
    Andrea Rovai likes this.

Share This Page