Websocket server implementing a clock handling alarms and timezones
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Yann Weber c63732b5a3 Initial commit před 3 roky
pyws_clock Initial commit před 3 roky
.gitignore Initial commit před 3 roky
README.md Initial commit před 3 roky
config.ini.inc Initial commit před 3 roky
logrotate_pyws_clock.inc Initial commit před 3 roky
nginx_server.conf Initial commit před 3 roky
pyws_clock.service.inc Initial commit před 3 roky
requirements.txt Initial commit před 3 roky
run_server.sh Initial commit před 3 roky

README.md

PyWSClock

Websocket clock server, handling timezones and alarms.

Dependencies

  • Python >= 3.9
  • python3-dateutil 2.8.1
  • python3-websockets 8.1

Debian-based dependencies installation

apt install python3-dateutil python3-websockets

Installing dependencies using pip

pip3 install -r requirements.txt

Running the server

python3 -m pyws_clock

Get some help using python3 -m pyws_clock --help

Deployment

Systemd service will run the server using the run_server.sh script. This script runs python3 -m pyws_clock -C config.ini allowing to configure the daemon with a config.ini file.

Create a configuration file

cp config.ini.inc config.ini; edit config.ini

Create a systemd service

cp pyws_clock.service.inc pyws_clock.service
edit pyws_clock.service
cp pyws_clock.service /etc/systemd/system/
systemctl enable pyws_clock.service
systemctl start pyws_clock.service
systemctl status pyws_clock.service

Testing the websocket server

Run this command and send a dummy session id by pressing enter. python3 -m websockets ws://127.0.0.1:8901

Example deployment on Debian 11

adduser --system pyws_clock
cp -R pyws_clock /home/pyws_clock/
cd /home/pyws_clock/pyws_clock/

cp config.ini.inc config.ini
echo "session_directory=/var/run/pyws_clock/sessions/
logfile=/var/log/pyws_clock/pyws_clock.log" >> config.ini

cp pyws_clock.service.inc pyws_clock.service
echo -e "User=pyws_clock
Group=nogroup
WorkingDirectory=/home/pyws_clock/pyws_clock/
ExecStart=/home/pyws_clock/pyws_clock/run_server.sh" >> pyws_clock.service
mv pyws_clock.service /etc/systemd/system/

# log dir & rotation config
mkdir /var/log/pyws_clock/
chown pyws_clock: /var/log/pyws_clock
cp logrotate_pyws_clock.inc /etc/logrotate.d/pyws_clock
systemctl restart logrotate

# session directory creation
mkdir -p /var/run/pyws_clock/sessions/
chown -R pyws_clock: /var/run/pyws_clock

# Enabling & starting the systemd service
systemctl enable pyws_clock.service
systemctl start pyws_clock.service
systemctl status pyws_clock.service

Nginx configuration

A sample configuration is available in nginx_server.conf.