Toadfarm::Manual::RunningToadfarm - Command line options
This manual goes through different options on how to start your Toadfarm application.
You can see the different options by simply running your application with no options:
$ /path/to/your-script $ /path/to/your-script help
In addition to all the default commands, Toadfarm adds some more:
Toadfarm::Command::start
$ /path/to/your-script start
Will only start your application if not running.
Toadfarm::Command::stop
$ /path/to/your-script stop
Will stop your application. Note that this command waits for the application to stop, which could take several seconds.
Toadfarm::Command::reload
$ /path/to/your-script reload
Will either start the application or hot deploy it. This means loading in a new version of your application, without losing any connections.
Your script can be used as an init-script. Example script:
#!/path/to/your/perl eval 'exec /path/to/your/perl -S $0 ${1+"$@"}' if 0; # not running under some shell ### BEGIN INIT INFO # Provides: toadfarm # Required-Start: $local_fs $network mysql postgresql # Required-Stop: $local_fs $network mysql postgresql # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: Toadfarm web application ### END INIT INFO use Toadfarm -init; run_as "www-data"; # logging, mount, plugins, ... start;
You can put the code above in /etc/init.d/your-script:
/etc/init.d/your-script
# Create a toadfarm script in init.d $ sudo $EDITOR /etc/init.d/your-script # Make it executable $ sudo chmod +x /etc/init.d/your-script # Make it start on boot $ sudo update-rc.d your-script defaults;
Remember that the hashbang can be anything, so if you have Toadfarm and Mojolicious running under plenv or Perlbrew you need to change the hashbang part to something like:
#!/home/USERNAME/.plenv/versions/5.21.11/bin/perl5.21.11 #!/home/USERNAME/perl5/perlbrew/perls/perl-5.16.0/bin/perl
If you want to use crontab to start your script, you can do it with this line:
* * * * * /path/to/your-script start 1>/dev/null 2>/dev/null
The trick here is to use "start" which will only start your server and not hot deploy it if it's already running.
It is possible to start the server using the standard Mojolicious tools as well:
$ /path/to/your-script daemon --listen http://*:5000 $ morbo /path/to/your-script $ hypnotoad /path/to/your-script
Setting up iptables rules will allow Toadfarm to listen to port 8080, while still receiving traffic on the default port. This way you can start and run toadfarm as a normal user instead of "root".
toadfarm
$ iptables -A PREROUTING -i eth0 -p tcp -m tcp --dport 80 -j REDIRECT --to-ports 8080 $ iptables -A PREROUTING -i eth0 -p tcp -m tcp --dport 443 -j REDIRECT --to-ports 8443
(You need to replace "eth0" with the appropriate interface)
You need to use Mojolicious::Plugin::SetUserGroup if you want to start Toadfarm as root and then change to a less priviledged used in the workers. Example:
# logging, mount, ... plugin SetUserGroup => {user => "www-data"}; start ["http://*:80"];
See also Toadfarm::Manual::Intro and Toadfarm::Manual::Config.
Jan Henning Thorsen - jhthorsen@cpan.org
jhthorsen@cpan.org
To install Toadfarm, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Toadfarm
CPAN shell
perl -MCPAN -e shell install Toadfarm
For more information on module installation, please visit the detailed CPAN module installation guide.