Permalink
Browse files

added a simple init script

  • Loading branch information...
1 parent c0e193f commit ffadacb877d0151137af8b85fe015cbd27b9f44e @rizen rizen committed Jul 9, 2012
View
@@ -0,0 +1,5 @@
+export PATH=/data/apps/bin:/data/apps/sbin:$PATH
+export LD_RUN_PATH=/data/apps/lib:$LD_RUN_PATH
+export LD_LIBRARY_PATH=/data/apps/lib:$LD_LIBRARY_PATH
+export ANY_MOOSE=Moose
+
View
@@ -0,0 +1,52 @@
+#!/data/apps/bin/perl
+
+use strict;
+use Config::JSON;
+use Template;
+use Getopt::Long;
+use File::Path qw(make_path);
+
+my $project = '';
+GetOptions("project=s" => \$project);
+
+die "usage: $0 --project=ProjectName" unless $project;
+$project = ucfirst $project;
+
+# make folder
+make_path('/data/'.$project.'/lib/'.$project.'/DB/Result');
+make_path('/data/'.$project.'/etc');
+make_path('/data/'.$project.'/bin');
+make_path('/data/'.$project.'/var');
+
+# set up default configs
+my $config = Config::JSON->new('/data/Wing/var/init/etc/example.conf');
+my $new_config = Config::JSON->create('/data/'.$project.'/etc/'.lc($project).'.conf');
+$new_config->config($config->config);
+$new_config->set('mkits', '/data/'.$project.'/var/mkits/');
+$new_config->set('app_namespace', $project);
+$new_config->set("log4perl_config", "/data/".$project."/etc/log4perl.conf",);
+$new_config->write;
+
+# set up needed files
+my $tt = Template->new({INTERPOLATE => 1, EVAL_PERL => 1, ABSOLUTE => 1});
+my $vars = {project => $project};
+template($tt,'lib/DB.pm', $vars, 'lib/'.$project.'/DB.pm') || die $tt->error();
+template($tt,'lib/DB/Result/APIKey.pm', $vars, 'lib/'.$project.'/DB/Result/APIKey.pm');
+template($tt,'lib/DB/Result/APIKeyPermission.pm', $vars, 'lib/'.$project.'/DB/Result/APIKey.pm');
+template($tt,'lib/DB/Result/User.pm', $vars, 'lib/'.$project.'/DB/Result/User.pm');
+template($tt,'etc/log4perl.conf', $vars, 'etc/log4perl.conf');
+template($tt,'etc/mime.types', $vars, 'etc/mime.types');
+template($tt,'bin/start_web.sh', $vars, 'bin/start_web.sh');
+template($tt,'bin/start_rest.sh', $vars, 'bin/start_rest.sh');
+template($tt,'bin/restart_starman.sh', $vars, 'bin/restart_starman.sh');
+template($tt,'bin/stop_starman.sh', $vars, 'bin/stop_starman.sh');
+template($tt,'bin/web.psgi', $vars, 'bin/web.psgi');
+template($tt,'bin/rest.psgi', $vars, 'bin/rest.psgi');
+
+# set privs
+system('cd /data/'.$project.'/bin;chmod 755 *');
+
+sub template {
+ my ($tt, $from, $vars, $to) = @_;
+ $tt->process('/data/Wing/var/init/'.$from, $vars, '/data/'.$project.'/'.$to) || die $tt->error();
+}
View
@@ -0,0 +1,34 @@
+#!/usr/bin/env perl
+use lib '/data/[% project %]/lib', '/data/Wing/lib';
+use Dancer;
+use Wing::Rest::APIKey;
+use Wing::Rest::Session;
+use [% project %]::Rest::User;
+use Wing::Rest::Status;
+use Wing::Rest::NotFound;
+use Plack::Builder;
+
+
+my $app = sub {
+ my $env = shift;
+ $env->{'psgix.harakiri'} = 1;
+ my $request = Dancer::Request->new(env => $env);
+ Dancer->dance($request);
+};
+
+builder {
+ unless ($^O eq 'darwin') {
+ enable "Plack::Middleware::SizeLimit" => (
+ max_unshared_size_in_kb => '51200', # 50MB
+ # min_shared_size_in_kb => '8192', # 8MB
+ max_process_size_in_kb => '179200', # 175MB
+ check_every_n_requests => 3
+ );
+ }
+ enable 'CrossOrigin',
+ origins => '*', methods => ['GET', 'POST', 'PUT', 'DELETE'], max_age => 60*60*24*30, headers => '*';
+ enable 'MethodOverride',
+ header => 'X-HTTP-Method', param => 'X-HTTP-Method';
+ $app;
+};
+
@@ -0,0 +1,5 @@
+#!/bin/bash
+. /data/Wing/bin/dataapps.sh
+cd /data/[% project %]/bin
+export WING_CONFIG=/data/[% project %]/etc/[% project FILTER lower %].conf
+killall -HUP start_server
@@ -0,0 +1,6 @@
+#!/bin/bash
+. /data/Wing/bin/dataapps.sh
+cd /data/[% project %]/bin
+export WING_CONFIG=/data/[% project %]/etc/[% project FILTER lower %].conf
+start_server --port 5000 -- starman --workers 2 --user nobody --group nobody --preload-app rest.psgi
+
@@ -0,0 +1,6 @@
+#!/bin/bash
+. /data/Wing/bin/dataapps.sh
+cd /data/[% project %]/bin
+export WING_CONFIG=/data/[% project %]/etc/[% project FILTER lower %].conf
+start_server --port 5001 -- starman --workers 2 --user nobody --group nobody --preload-app web.psgi
+
@@ -0,0 +1,5 @@
+#!/bin/bash
+. /data/Wing/bin/dataapps.sh
+cd /data/[% project %]/bin
+export WING_CONFIG=/data/[% project %]/etc/[% project FILTER lower %].conf
+killall start_server
View
@@ -0,0 +1,27 @@
+#!/usr/bin/env perl
+use lib '/data/[% project %]/lib', '/data/Wing/lib';
+
+use Dancer;
+# your modules here
+use Wing::Web::NotFound;
+use Plack::Builder;
+
+my $app = sub {
+ my $env = shift;
+ $env->{'psgix.harakiri'} = 1;
+ my $request = Dancer::Request->new(env => $env);
+ Dancer->dance($request);
+};
+
+builder {
+ unless ($^O eq 'darwin') {
+ enable "Plack::Middleware::SizeLimit" => (
+ max_unshared_size_in_kb => '51200', # 50MB
+ # min_shared_size_in_kb => '8192', # 8MB
+ max_process_size_in_kb => '179200', # 175MB
+ check_every_n_requests => 3
+ );
+ }
+ enable 'MethodOverride', header => 'X-HTTP-Method', param => 'X-HTTP-Method';
+ $app;
+};
@@ -7,10 +7,10 @@
],
"mkits" : "/data/PROJECT/var/mkits/",
"app_namespace" : "PROJECT",
- "tenants" : {
- "namespace" : "PROJECTSITE",
- "db_driver" : { "prefix" : "DBI:mysql:database=", "suffix" : ""}
- },
+# "tenants" : {
+# "namespace" : "PROJECTSITE",
+# "db_driver" : { "prefix" : "DBI:mysql:database=", "suffix" : ""}
+# },
"log4perl_config" : "/data/PROJECT/etc/log4perl.conf",
#"dbic_trace" : "/tmp/dbic.trace.out",
"rpc_limit" : 30,
@@ -1,6 +1,6 @@
log4perl.logger = DEBUG, mainlog
log4perl.appender.mainlog = Log::Log4perl::Appender::File
-log4perl.appender.mainlog.filename = /var/log/PROJECT.log
+log4perl.appender.mainlog.filename = /var/log/[% project %].log
log4perl.appender.mainlog.layout = PatternLayout
log4perl.appender.mainlog.layout.ConversionPattern = %d %p %m %n
File renamed without changes.
View
@@ -0,0 +1,11 @@
+package [% project %]::DB;
+
+use Moose;
+use utf8;
+no warnings qw(uninitialized);
+extends qw/DBIx::Class::Schema/;
+
+__PACKAGE__->load_namespaces();
+
+no Moose;
+__PACKAGE__->meta->make_immutable;
@@ -0,0 +1,11 @@
+package [% project %]::DB::Result::APIKey;
+
+use Moose;
+use Wing::Perl;
+extends 'Wing::DB::Result';
+with 'Wing::Role::Result::APIKey';
+
+__PACKAGE__->wing_finalize_class( table_name => 'api_keys');
+
+no Moose;
+__PACKAGE__->meta->make_immutable(inline_constructor => 0);
@@ -0,0 +1,12 @@
+package [% project %]::DB::Result::APIKeyPermission;
+
+use Moose;
+use Wing::Perl;
+extends 'Wing::DB::Result';
+with 'Wing::Role::Result::APIKeyPermission';
+
+__PACKAGE__->wing_finalize_class( table_name => 'api_key_permissions');
+
+no Moose;
+__PACKAGE__->meta->make_immutable(inline_constructor => 0);
+
@@ -0,0 +1,13 @@
+package [% project %]::DB::Result::User;
+
+use Moose;
+use Wing::Perl;
+extends 'Wing::DB::Result';
+with 'Wing::Role::Result::User';
+
+__PACKAGE__->wing_finalize_class( table_name => 'users');
+
+
+no Moose;
+__PACKAGE__->meta->make_immutable(inline_constructor => 0);
+

0 comments on commit ffadacb

Please sign in to comment.