Ubuntu no server install

General Discussion

Ubuntu no server install

Postby TD22057 » Thu Aug 17, 2017 9:26 am

I just finished getting the webapp to work on my Ubuntu 14.04LTS server. I'm not running nginx and since this won't be exposed outside of my LAN, I wanted to just use the simple servers built in to flask/gunicorn to handle the web pages. In case anyone wants to do something similar, here's what I did to get this to work.

Everything is running as user 'ad2usb', so create a local user and give them access to the serial lines.

Code: Select all
sudo useradd -r -s /bin/false ad2usb
sudo addsuser ad2usb dialout


I first installed ser2sock and wrote an upstart file so that can launch on startup using the ad2usb user. Let me know if you want a copy of that file (or write your own init.d or systemd file depending on your OS). Use telnet to check that ser2sock is working and that you can receive and send commands to your panel.

The web app has a lot of hard coded paths and ports so I chose to install it in that location (/opt/alarmdecoder-webapp) though I did edit the code to use a different port number (22000). Just grep for 5000 in the python code to find the files that need to be modified to change the port.

Code: Select all
# Get the web application source code
cd /opt
sudo git clone https://github.com/nutechsoftware/alarmdecoder-webapp.git

# Change the source to your local user - this makes it easier to edit and test until things are working.
sudo chown -R [USER] alarmdecoder-webapp

# Install the python dependencies using virtualenv to avoid conflicts with the system.  This assumes you're using a bash shell.
cd /opt/alarmdecoder
sudo apt-get install python-virtualenv python-pip
virtualenv pyenv
. pyenv/bin/activate
pip install alarmdecoder
pip install gunicorn
pip install -r requirements.txt

# Create a script to run the server.
cat << EOF > run.sh
#!/bin/sh

cd /opt/alarmdecoder-webapp
. pyenv/bin/activate

gunicorn --name alarmdecoder \\
    --worker-class=socketio.sgunicorn.GeventSocketIOWorker \\
    --env=POLICY_SERVER=0 \\
    --workers=1 \\
    --log-file /var/log/alarmdecoder.log \\
    --timeout=120 \\
    wsgi:application
EOF

chmod a+x run.sh

# Initialize the database.
python manage.py initdb

# Try running in debug mode to make sure things work.
python manage.db run
firefox localhost:5000

# ctrl-c to kill the debug server above and try the run script
./run.sh
firefox localhost:5000

# Assuming all of that works fine, create an upstart/init.d/systemv file to execute run.sh as the ad2usb user
# Change the files to be owned by ad2usb
sudo chown -R ad2usb:dialout /opt/alarmdecoder-webapp

# Start the service (upstart).  Errors can be found at /var/log/upstart/alarmdecoder-webapp.log
sudo service alarmdecoder-webapp start
TD22057
newt
newt
 
Posts: 12
Joined: Tue Aug 15, 2017 9:22 am

Re: Ubuntu no server install

Postby kevin » Thu Aug 17, 2017 9:34 am

Thanks for the guide! Very cool.

Just a note on pathing - the only things that are "hardcoded" currently are the alarmdecoder library to satisfy the ALARMDECODER_LIBRARY_PATH constant as well as the /etc/ser2sock/ser2sock.conf path

Everything else is based off of INSTANCE_FOLDER_PATH variable or current working directory.

You can modify INSTANCE_FOLDER_PATH if you want to put webapp elsewhere.
Not an employee of the company. Just here to help and keep things clean.
kevin
Platinum Nut
Platinum Nut
 
Posts: 994
Joined: Fri Aug 16, 2013 10:10 am


Return to General

Who is online

Users browsing this forum: No registered users and 1 guest

cron