2

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.

tejas
  • 1,795
  • 1
  • 16
  • 34

3 Answers3

1

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.

  • Just to make clear: `systemctl enable` and `systemctl start` are different and independent things. `enable` means _"autostart at boot time"_ while `start` means _"start now"_. Of course you can do both: `start` for _now_ and `enable` for _autostart_. I think there's also an option to _enable and start now_ in one step, but I forgot which it was. – PerlDuck Dec 21 '16 at 15:56
0

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

tejas
  • 1,795
  • 1
  • 16
  • 34
  • `.bashrc` will run when you login [to an interactive shell session](https://unix.stackexchange.com/a/129144/209677), you say _on boot_, not _on a user login_. – Pablo Bianchi May 10 '18 at 17:17
-1

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