-
Notifications
You must be signed in to change notification settings - Fork 1
/
run
executable file
·139 lines (131 loc) · 4.3 KB
/
run
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#!/bin/sh
# NAME
# daemontools-plack-runner - Shell Script To Bootstrap Plack Apps From Daemontools
#
# DESCRIPTION
# Generic run file to execute plack with daemontools
#
# ASSUMPTIONS
# * ALL perl dependencies are available via a local::lib
# directory (default extlib)
# * Requires daemontools (duh)
# * Requires Plack (duh)
# * Requires local::lib
# In many cases, local::lib MUST BE INSTALLED GLOBALLY,
# NOT your ~/perl5. If in doubt, install globally.
# Otherwise, use PERL5LIB in your env dir
# * Requires Server::Starter (start_server script)
#
# USAGE SCENARIO
# How /I/ use this with daemontools:
# (1) mkdir /var/lib/svscan/myapp
# (2) copy/symlink this file to /var/lib/svscan/myapp
# (3) create /var/lib/svscan/myapp/catalyst.yaml
# (4) mkdir /var/lib/svscan/myapp/env
# (5) this env dir should contain files that have your settings.
# for example, if you want to use hoge.psgi as your PSGI app,
# create a file named PSGI_APP with "hoge.psgi" as its content.
# (6) ln -s /var/lib/svscan/myapp /etc/service (or /service)
#
# How /I/ use this in a Standalone deployment (for testing)
# (1) create a directory like myapp/deploy (doesn't really matter)
# (2) copy/symlink this file to /var/lib/svscan/myapp
# (3) mkdir /var/lib/svscan/myapp/env
# (4) create env files like (5) above
# (5) ./deploy/run woot!
#
# OFTEN USED VARIABLES:
#
# APP_HOME
# Location of your application files, directories, whatever.
# Default: current directory
# APP_USER
# Username to run the application as
# Default: www
# CATALYST_CONFIG
# Location of your Catalyst config file. You can ignore it
# if you're not running Catalyst
# Default: catalyst.yaml
# CATALYST_HOME
# Location of your Catalyst files. You can usually ignore it.
# Default: $APP_HOME
# EXTLIB
# Location of your local::lib directory.
# Default: $APP_HOME/extlib
# EXTRA_ARGS
# Anything else you want to pass to plackup. For example, if you're
# using Starman, you may want to specify --max-requests and --workers
# PERL
# Location of your Perl binary.
# Default: Result of `type -p perl`
# PLACK_HANDLER
# The name of Plack handler to use.
# Default: Starman
# PLACKUP_SCRIPT
# Location of your plackup script
# Default: $EXTLIB/bin/plackup
# PORT
# Port to listen to
# Default: 5000
# PSGI_FILE
# Location of your PSGI app file.
# Default: app.psgi
# START_SERVER_SCRIPT
# Location of your start_server script
# Default: $EXTLIB/bin/start_server
#
# OTHER VARIABLES
# Variables that this file does NOT directly use, but are usually
# helpful when I'm debugging:
#
# DEBUG
# A lot of things acknowledge this ;)
# DBI_TRACE / DBIC_TRACE
# Enables tracing for DBI/DBIC
#
# COPYRIGHT
# Copyright (c) 2010 Daisuke Maki
#
# LICENSE
# This program is free software; you can redistribut it and/or modify it
# under Artistic License 2.0
# http://www.perlfoundation.org/artistic_license_2_0
#
# AUTHORS
# Original run file by Daisuke Maki
# envdir fixes and polishing by Hirose Masaaki
exec 2>&1
ABSPATH=$(cd ${0%/*} && echo $PWD/${0##*/})
THISDIR=$(dirname $ABSPATH)
APP_HOME=$(pwd -P)
PSGI_FILE=app.psgi
EXTRA_ARGS=
ENVDIR=env
PERL=$(which perl)
[ -f "catalyst.yaml" ] && CATALYST_CONFIG=$THISDIR/catalyst.yaml
[ -f $THISDIR/app.psgi ] && PSGI_FILE=$THISDIR/app.psgi
[ -d $THISDIR/env ] && ENVDIR=$THISDIR/env
exec env - \
PATH=$PATH \
APP_HOME=$APP_HOME \
CATALYST_HOME= \
CATALYST_CONFIG=$CATALYST_CONFIG \
PLACK_HANDLER=Starman \
PSGI_FILE=$PSGI_FILE \
PORT=5000 \
PERL=$PERL \
APP_USER=www \
EXTRA_ARGS="$EXTRA_ARGS" \
envdir $ENVDIR \
sh -c '
[ -z $CATALYST_HOME ] && CATALYST_HOME=$APP_HOME ;
[ -z $EXTLIB ] && EXTLIB=$APP_HOME/extlib;
[ -z $START_SERVER_SCRIPT ] && START_SERVER_SCRIPT=$EXTLIB/bin/start_server;
[ -z $PLACKUP_SCRIPT ] && PLACKUP_SCRIPT=$EXTLIB/bin/plackup
exec setuidgid $APP_USER \
$PERL -Mlocal::lib=$EXTLIB \
$START_SERVER_SCRIPT --port $PORT -- \
$PERL -Mlocal::lib=$EXTLIB \
$PLACKUP_SCRIPT -s $PLACK_HANDLER -a $PSGI_FILE -p $PORT $EXTRA_ARGS
'
exit