How do I start plack application on boot

714 Views Asked by At

Does anyone know how to start a plack application on boot.

The os is raspbian(raspberry pi). I think i have run it as a normal user(pi). That's how i start it manually.

I have tried adding something like this to rc.local but without success

su pi -c 'cd /path/to/app && plackup -d -p 5000 -r -R ./lib,./t -a ./bin/app.psgi &'

This will in-turn be used by Apache and the app is written in dancer2 if it makes any difference.

3

There are 3 best solutions below

1
tejas On BEST ANSWER

The issue was that the perl 5 environment variables were not initialised (which are in .bashrc).

so the solution was to run the plackup command inside bash -i so that it reads .bashrc or set the PERL5LIB before invoking plackup

1
HermenLesscher On

On a raspberry pi I use systemd to create and start a service, in the file: /etc/systemd/system/dancer.service

[Unit]
Description=NCI Starman Dancer App
After=syslog.target

[Service]
Type=forking
ExecStart=/usr/local/bin/starman --daemonize -l 127.0.0.1:3004 \
  --user myuser --group myuser --workers 8 -D -E production \
  --pid /var/run/dancer.pid -I/home/myuser/webservers/Dancer/lib \
  --error-log=/home/myuser/logs/dancer_error.log \
  /home/myuser/webservers/Dancer/bin/app.psgi
Restart=always

[Install]
WantedBy=multi-user.target

And then I enable this with systemctl enable dancer.service Or start it manually with systemtctl start dancer.service

Instead of startman, you can of course use plackup.

1
Nick Knutov On

You may also want to use monit or supervisord to be sure your app is always run and will be restarted in case of kill by any reason, for example OOM