Dancer2-Plugin-WebService
view release on metacpan or search on metacpan
CREATE_SAMPLE_APPLICATION view on Meta::CPAN
To start your application as Linux service
If you plan to use a reverse proxy change the listening IP (BIND) from 0.0.0.0 to 127.0.0.1
Locate the plackup with "find /usr/bin -name plackup -type f" e.g /usr/bin/site_perl/plackup
Edit/create the file /etc/systemd/system/TestService.service
[Unit]
Description=TestService rest API
Documentation=https://metacpan.org/pod/Dancer2
After=network.target
ConditionPathExists=/usr/bin/site_perl/plackup
[Service]
Type=simple
User=dancer
Group=dancer
Environment=BIND=0.0.0.0
Environment=PORT=3000
Environment=WORKERS=10
Environment=ENVIROMENT=development
ExecStart=/usr/bin/site_perl/plackup --host $BIND --port $PORT --env $ENVIROMENT --server Starman --workers=$WORKERS --app /home/dancer/TestService/bin/app.psgi
WorkingDirectory=/home/dancer/TestService
ExecStop=/bin/kill -s QUIT $MAINPID
KillMode=mixed
KillSignal=QUIT
StandardOutput=journal
StandardError=journal
NoNewPrivileges=true
PrivateTmp=true
LimitNOFILE=infinity
Restart=on-failure
RestartSec=60s
[Install]
WantedBy=multi-user.target
start the service
systemd-analyze verify /etc/systemd/system/TestService.service
systemctl daemon-reload
systemctl cat TestService
systemctl enable TestService.service
systemctl start TestService
systemctl is-active TestService
systemctl status TestService
journalctl -f -xelu TestService
systemctl stop TestService
delete the service
systemctl stop TestService
systemctl disable TestService.service
unlink /etc/systemd/system/TestService.service
If you use an nginx web server to reverse proxy you service your app
vi nginx.conf
...
upstream TestService { server 127.0.0.1:3000 fail_timeout=0; keepalive 1024; }
...
server
{
server_name www.example.com;
listen 30080;
listen 30443 ssl;
root /tmp;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr; # needed for real client IP pass as server enviroment variable HTTP_X_REAL_IP
location /
{
fastcgi_param REMOTE_ADDR X-Real-IP;
proxy_pass http://TestService;
}
}
( run in 1.893 second using v1.01-cache-2.11-cpan-39bf76dae61 )