<aside> ⚠️ Complete the Database Configuration step before moving on. These instructions require that psycopg2 is already installed.

</aside>

Initial Configuration

On your server, clone the code available on the Github repository: .

https://github.com/NSFCUSWIFTPASS/RF_survey

All relevant code for the server configuration can be found in the server folder.

The data organization and processing code depends on a number of Python packages. Depending on your system, you might still need to install numpy. If you haven’t done so yet, install it with:

Keep an eye out for errors and install any further missing Python packages.

Where to store Data

A large part of the initial server configuration depends on where you decide to store the data. If you decide to store the data in a directory that requires root access for changes, e.g. /data/..., you will need to move the server directory to a root user and make it executable. If you instead store the data in a user level, e.g. /home/user/data/..., you might be able to skip a lot of the configuration in the next steps.

Storage dependent Configuration: root

If you decide to store your data in a root level directory, you will need to move the server directory to /root/. The code is already configured with the assumption that it is located at /root/server. You will also need to make the code executable with sudo chmod +x to be able to execute the code with cron. You may also want to edit lines 88 and 89 to determine what directory the Watchdog will be watching and to which directory it will be writing, if /data/sync and /data are not where you would like the data to be stored. Additionally, change line 31 in Organizer.py to begin with the directory where you would like your data to be moved to and processed from. Make sure that line 45 in statistics.py is watching the same directory.

Finally, you need to open the sudo crontab with sudo crontab -e and add the following lines:

* * * * * /root/server/Watcher.sh
* * * * * /root/server/Stats.sh
*/30 * * * * /usr/bin/python3 /root/server/kill_watcher.py
*/30 * * * * /usr/bin/python3 /root/server/kill_stats.py

You might notice, and find it curious, that cron is configured to attempt to start the Watchdog once very minute, while also killing the Watchdog every 30 minutes. First, the shell scripts check whether a Watcher or statistics process is already running. If a process is already running, nothing will be executed. If the process is not running, it will be executed. Second, due to a bug in the Python Watchdog package, the Watcher will stop working after a certain amount of time. While several fixes have been attempted, killing and restarting the process every 30 minutes so far seems to work.

<aside> 💡 The Watcher process is not abruptly killed. The same code that asks the survey code to quit at the next convenient time is used to stop the Watcher. It will finish first what it is doing and then exit.

</aside>

Storage dependent Configuration: user

Since the code on Github has been configured with a root user in mind, files require some minor changes if you decided to store the survey data in a user directory. Let’s assume you decided to store data in /home/user/data. Make the following changes: