# Codename One deployment template -- see ../../references/deployment.md.
# Replace myapp with the project's name and app.example.com with the domain. The binary
# is named after the backend module's artifactId: backend/target/myapp-backend here.
# Once: apt-get install -y certbot && certbot certonly --standalone -d app.example.com
# /etc/myapp/env, when the server terminates TLS itself. Remove CN1_SERVER_ADDRESS,
# CN1_SERVER_FORWARDHEADERS, CN1_SERVER_TRUSTEDPROXIES and CN1_SESSION_SECURE:
# there is no proxy, and a server bound to 127.0.0.1 can't be reached on 443.
CN1_SERVER_PORT=443
CN1_SERVER_TLS_CERTIFICATE=/etc/myapp/tls/fullchain.pem
CN1_SERVER_TLS_KEY=/etc/myapp/tls/privkey.pem

# myapp.service, under [Service]: a port below 1024 without running as root
AmbientCapabilities=CAP_NET_BIND_SERVICE

# /etc/letsencrypt/renewal-hooks/deploy/myapp -- chmod 755. The server reads the
# files when it starts, so a renewed certificate needs a restart.
#!/bin/sh
install -o myapp -g myapp -m 600 -D \
    /etc/letsencrypt/live/app.example.com/fullchain.pem /etc/myapp/tls/fullchain.pem
install -o myapp -g myapp -m 600 -D \
    /etc/letsencrypt/live/app.example.com/privkey.pem /etc/myapp/tls/privkey.pem
systemctl restart myapp
# After the first `certbot certonly`, run the hook once by hand: certbot runs it only on renewals.
