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

I tested this on both Synology DS213 and DS214.

 

WARNING: This recipe runs web2py with root permissions. Make the necessary changes if you need it to be secure.

 

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

I installed the Pyhton Module addon because it installs several Python modules that are useful. You can do this using the NAS web interface.

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

 

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

 

Download web2py source from http://www.web2py.com/examples/static/web2py_src.zip and copy it to ~ (usually /root) on the NAS. You can download it directly from the SSH remote shell or from a Windows PC and copy it using the above mentioned WinSCP.

Don't forget to unzip it using the SSH remote shell.

 

To use pip to install other packages, do this:

Download get-pip.py from https://pip.pypa.io/en/latest/installing.html#install-pip and copy it to ~ 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 and copy it to /usr/syno/etc/rc.d on the NAS.
The file contents should be:

 

#!/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

Related slices

Comments (1)


Hosting graciously provided by:
Python Anywhere