If you benefit from web2py hope you feel encouraged to pay it forward by contributing back to society in whatever form you choose!

Hello,

 

I tested this on both Synology DS213 and DS214.

 

WARNING: This runs web2py as root. Make the necessary changes if you need security.

 

Check that the SSH protocol is activated on the NAS, using its web interface.

 

I use PuTTY to access the command line and WinSCP to copy files/folders between my Windows PC and the NAS.

 

I installed the Python Module on the Package Center, using the NAS web interface, because it has several useful modules.

 

All pre-installed Python packages are located at /usr/local/lib/python2.7/site-packages.

 

Logon on the NAS (SSH remote shell), using root as username and your admin password.

 

Download web2py source code from http://www.web2py.com/examples/static/web2py_src.zip and copy it to /root on the NAS.

Don't forget to unzip it.

 

Download get-pip.py from https://pip.pypa.io/en/latest/installing.html#install-pip and copy it to /root on the NAS.

Run the following command on the NAS, using the SSH remote shell, to install pip

python get-pip.py

 

All pip installed packages are located at /lib/python2.7/site-packages.

 

To manage web2py daemon and make it autorun on startup, create a file called S99web2py.sh with the contents below and copy it to /usr/syno/etc/rc.d

 

#!/bin/sh
# This script allows web2py to be started and stopped on a Synology NAS
# copy this script to /usr/syno/etc/rc.d

prog="/root/web2py/web2py.py"

web2py_start ()
{
  nohup python2 $prog -c /root/web2py/ssl_certificate.crt -k /root/web2py/ssl_self_signed.key -i 0.0.0.0 -a "<recycle>" >>/dev/null 2>/dev/null &
  pid=`ps | grep $prog | tail -2 | head -1 | awk '{print $1}'`
  if [ "x$pid" != "x$$" ]
  then
      echo "WEB2PY has been started (pid $pid). Stop it with '$0 stop'"
  else
    echo "Failed to start WEB2PY."
  fi
}

web2py_stop ()
{
  pcount="`ps | grep -c $prog`"
  if [ "x$pcount" == "x1" ]
    then
    echo "No WEB2PY processes to stop."
  else
    pid=`ps | grep -m 1 $prog | awk '{print $1}'`
    kill -15 $pid
    # Wait for web2py to shut down gracefully.
    sleep 2
    pcount="`ps | grep -c $prog`"
    if [ "x$pcount" == "x1" ]
    then
      echo "WEB2PY has been stopped."
    else
      echo "Failed to stop WEB2PY. (Possibly, only one of several web2py processes was killed.)"
      echo "Still running:"
      ps | grep $prog | tail -2 | head -1
    fi
  fi
}

case "$1" in
  start)
    web2py_start
  ;;
  stop)
    web2py_stop
  ;;
  restart)
    web2py_stop
    web2py_start
  ;;
  *)
    echo "Usage: $0 [start|stop|restart]"
  ;;
esac

exit 0

 

Enjoy,

 

João Matos

 

Related slices

Comments (0)


Hosting graciously provided by:
Python Anywhere