Dancer2-Plugin-WebService
view release on metacpan or search on metacpan
CREATE_SAMPLE_APPLICATION view on Meta::CPAN
As an example lets create the "TestService" application
We need a non-privileged user e.g dancer
sudo -u dancer dancer2 gen --application TestService --directory TestService --path /home/dancer --overwrite
[ -d /var/lib/WebService/TestService ] || /usr/bin/mkdir -p /var/lib/WebService/TestService
[ -d /var/log/WebService ] || /usr/bin/mkdir /var/log/WebService
cp /home/dancer/TestService/environments/production.yml /home/dancer/TestService/environments/production.yml.orig
cp /home/dancer/TestService/environments/development.yml /home/dancer/TestService/environments/development.yml.orig
cp /home/dancer/TestService/config.yml /home/dancer/TestService/config.yml.orig
/usr/bin/chown -R dancer:dancer /var/lib/WebService/TestService /home/dancer/TestService /var/log/WebService
The custom routes with your code are stored at the file /home/dancer/TestService/lib/TestService.pm
Configure the firewall to listen e.g at port 3000
# Redhat
firewall-cmd --zone=public --permanent --add-port=3000/tcp
firewall-cmd --reload
firewall-cmd --list-all
getent passwd dancer >/dev/null || useradd -g dancer -l -m -c "Dancer2 WebService" -s $(/usr/bin/which nologin) dancer
lslogins dancer
For linux native authentication we need to create a user, lets call him joe
getent passwd joe > /dev/null || useradd -m -c 'I am a dancer' joe
usermod --password $(openssl passwd -6 -salt pCt6qNtCYsozKMDu SomePassword) joe # Now joe's password is SomePassword
Create the Persistent session data and log directories. You can change them later if needed
i=/var/lib/WebService; [ -d $i ] || { /usr/bin/mkdir $i; /usr/bin/chown -R dancer:dancer $i; }
i=/var/log/WebService; [ -d $i ] || { /usr/bin/mkdir $i; /usr/bin/chown -R dancer:dancer $i; }
Use logrotate for housekeeping the log files
vi /etc/logrotate.d/WebService
/var/log/WebService/*.log {
create 640 dancer dancer
compress
missingok
notifempty
daily
lib/Dancer2/Plugin/WebService.pm view on Meta::CPAN
curl $url/logout?token=17393926-5c8-0
curl $url/logout -d '{"token":"17393926-5c8-0"}' -H "$H" -X POST
=head1 Plugin Installation
You should your run your APIs as a non privileged user e.g. the "dancer"
getent group dancer >/dev/null || groupadd dancer
getent passwd dancer >/dev/null || useradd -g dancer -l -m -c "Dancer2 WebService" -s $(which nologin) dancer
i=/var/lib/WebService; [ -d $i ] || { mkdir $i; chown -R dancer:dancer $i; }
i=/var/log/WebService; [ -d $i ] || { mkdir $i; chown -R dancer:dancer $i; }
cpanm Dancer2
cpanm Dancer2::Plugin::WebService
=head1 Create a sample application e.g. the "TestService"
Follow the I<CREATE_SAMPLE_APPLICATION> document to create the sample application I<TestService>
=head1 Start the application
To start it manual as user I<dancer> from the command line
( run in 0.534 second using v1.01-cache-2.11-cpan-71847e10f99 )