Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 261 lines (225 sloc) 8.089 kB
fdfdd8e @klacke prep for 1.80
klacke authored
1 /* win32 version of yaws starup script */
2 /* Author: klacke@hyber.org (Jan 2009) */
3
4
7871338 @klacke win32 work
klacke authored
5 #include <windows.h>
6 #include <stdio.h>
7
8 #define BSIZ 16000
9
10 static unsigned char path[BSIZ];
11 static unsigned char *fpath;
12
13 static void readreg() {
14 HKEY hKey;
15 unsigned int bsz = BSIZ;
16 // Check where yaws is installed, we need to -pa that path
17 if (RegOpenKeyEx(HKEY_LOCAL_MACHINE,
18 "SOFTWARE\\Hyber\\Yaws",
19 0, KEY_READ, &hKey) != ERROR_SUCCESS)
20 {
21 printf ("Cannot find yaws installation in the registry\n");
22 exit(1);
23 }
24 memset(path, 0, BSIZ);
fdfdd8e @klacke prep for 1.80
klacke authored
25 int ret = RegQueryValueEx(hKey, "DIR", NULL, NULL, path, &bsz);
7871338 @klacke win32 work
klacke authored
26 fpath = (unsigned char*)malloc(strlen(path));
27 int i;
28 for(i = 0; i<strlen(path); i++ ) {
29 if (path[i] == '\\') {
30 fpath[i] = '/';
31 }
32 else
33 fpath[i] = path[i];
34 }
35 fpath[i] = 0;
36
37 }
38
39
40 int charg(char **argv, char *s1, char *s2, int p) {
41 if (strcmp(s1, argv[p]) == 0) return 1;
42 if ((s2 != NULL) && strcmp(s2, argv[p]) == 0) return 1;
43 return 0;
44 }
45
46
fdfdd8e @klacke prep for 1.80
klacke authored
47 int runwait(char *execString) {
48
49 STARTUPINFO si = { sizeof(si) };
50 PROCESS_INFORMATION pi;
51
52 //printf("execString: %s \n", execString);
53
54 if(CreateProcess(0, execString, NULL, NULL, FALSE, 0, 0, 0, &si, &pi))
55 {
56 unsigned long ret = 0;
57
58 // wait for process to finish
59 WaitForSingleObject(pi.hProcess, INFINITE);
60 if (GetExitCodeProcess(pi.hProcess, &ret) == 0)
61 ret = 1;
62 CloseHandle(pi.hProcess);
63 CloseHandle(pi.hThread);
64 return ret;
65 }
66 printf("Failed to create the process entirely\n");
385ae07 @klacke Better error msg if erl is not found for win32 users
klacke authored
67 printf("Tried to invoke: <%s> \n", execString);
68 printf("Make sure you have <erl> in your environment PATH \n");
fdfdd8e @klacke prep for 1.80
klacke authored
69 return 1;
70 }
71
72
73
74 int nosh(char *s) {
75 char buf[BUFSIZ];
76 sprintf (buf, "erl -noshell -pa \"%s/ebin\" %s ", fpath, s);
77 return runwait(buf);
78 }
79
80 int help() {
81 printf("usage: "
82 ""
83 " yaws -i | --interactive -- interactive (no daemon) mode"
84 " yaws -w | --winteractive -- interactive (werl) "
85 " yaws --daemon -- daemon mode"
86 ""
87 ""
88 ""
89 " Auxiliary flags for the daemon: "
90 " --id Id -- set system id"
91 " --debug -- debug mode "
92 " --conf File -- set config file"
93 " --tracetraf -- trace traffic"
94 " --tracehttp -- trace http traffic"
95 " --traceout -- trace output to stdout"
96 " --version -- print version"
97 " --pa path -- add load path"
98 " --mnesiadir dir -- start Mnesia in dir"
99 " --sname xxx -- start with sname xxx"
100 " --name xxx -- start with name xxx"
101 " --runmod mod -- call mod:start/0 at startup"
102 " --erlarg X -- pass argument X to $erl"
103 ""
104 "ctl functions ... "
105 " yaws --hup [--id ID] -- hup the daemon, reload conf"
106 " yaws --stop [--id ID] -- stop the daemon "
107 " yaws --debug-dump [--id ID] -- produce a debug dump "
108 " yaws --status [--id ID] -- query the daemon status "
109 " yaws --load Modules -- load modules "
110 " yaws --ls -- list Yaws nodes and their status"
111 " yaws --ctltrace traffic|http -- toggle trace of running daemon");
112
113 return(0);
114 }
115
116
117
7871338 @klacke win32 work
klacke authored
118 int main(int argc, char**argv) {
119
fdfdd8e @klacke prep for 1.80
klacke authored
120 int interactive = 1;
7871338 @klacke win32 work
klacke authored
121 int winteractive = 0;
fdfdd8e @klacke prep for 1.80
klacke authored
122 int daemon = 0;
7871338 @klacke win32 work
klacke authored
123 char *conf = NULL;
fdfdd8e @klacke prep for 1.80
klacke authored
124 char *sname = NULL;
125 char *name = NULL;
7871338 @klacke win32 work
klacke authored
126 int debug = 0;
127 char *runmod = NULL;
fdfdd8e @klacke prep for 1.80
klacke authored
128 char *trace = NULL;
129 char *traceoutput = NULL;
130 char tbuf[BUFSIZ];
131 char paBuf[BUFSIZ];
132 char execString[BSIZ];
133 char mnesia[255];
134 char erlarg[255];
135 char *id = "default";
136
137 memset(paBuf, 0, BUFSIZ);
138 memset(tbuf, 0, BUFSIZ);
139 memset(execString, 0, BSIZ);
7871338 @klacke win32 work
klacke authored
140
141 readreg();
fdfdd8e @klacke prep for 1.80
klacke authored
142 sprintf(paBuf, " -pa \"%s/ebin\" ", fpath);
7871338 @klacke win32 work
klacke authored
143
144 int p = 1;
145 while (p < argc) {
fdfdd8e @klacke prep for 1.80
klacke authored
146 if (charg(argv, "-i", "--interactive", p)) {
7871338 @klacke win32 work
klacke authored
147 interactive = 1;
fdfdd8e @klacke prep for 1.80
klacke authored
148 }
149 else if (charg(argv, "-w", "--winteractive", p)) {
7871338 @klacke win32 work
klacke authored
150 winteractive = 1;
fdfdd8e @klacke prep for 1.80
klacke authored
151 }
152 else if (charg(argv, "-D", "--daemon", p)) {
153 interactive = winteractive = 0;
154 daemon = 1;
155 }
156 else if (charg(argv, "--debug", NULL, p)) {
7871338 @klacke win32 work
klacke authored
157 debug = 1;
fdfdd8e @klacke prep for 1.80
klacke authored
158 }
159 else if (charg(argv, "-t", "--tracetraf", p)) {
160 trace=" -yaws trace traffic ";
161 }
162 else if (charg(argv, "-T", "--tracehttp", p)) {
163 trace=" -yaws trace http ";
164 }
165 else if (charg(argv, "-x", "--traceout", p)) {
166 traceoutput = " -yaws traceoutput ";
167 }
168 else if (charg(argv, "--trace", NULL, p)) {
169 traceoutput = " -yaws traceoutput ";
170 trace = " -yaws trace traffic ";
171 }
172 else if (charg(argv, "--mnesiadir", "-M", p)) {
173 sprintf(mnesia, "-mnesia dir \"%s\" -run mnesia start ",argv[++p]);
174 }
175 else if (charg(argv, "-c", "--conf", p)) {
7871338 @klacke win32 work
klacke authored
176 conf = argv[++p];
fdfdd8e @klacke prep for 1.80
klacke authored
177 }
178 else if (charg(argv, "--id", NULL, p)) {
179 id = argv[++p];
180 }
181 else if (charg(argv, "-pa", NULL, p)) {
182 sprintf(tbuf, " -pa \"%s\" ", argv[++p]);
183 strcat(paBuf, tbuf);
184 }
185 else if (charg(argv, "--runmod", "-r", p)) {
7871338 @klacke win32 work
klacke authored
186 runmod = argv[++p];
fdfdd8e @klacke prep for 1.80
klacke authored
187 }
188 else if (charg(argv, "--hup", "-h", p)) {
189 return nosh("-s yaws_ctl hup default");
190 }
191 else if (charg(argv, "--stop", "-s", p)) {
192 return nosh("-s yaws_ctl stop default");
193 }
194 else if (charg(argv, "--status", "-S", p)) {
195 return nosh("-s yaws_ctl status default");
196 }
197 else if (charg(argv, "--debug-dump", NULL, p)) {
198 return nosh("-s yaws_ctl debug_dump default ");
199 }
200 else if (charg(argv, "--version", "-v", p)) {
201 nosh("-s yaws printversion");
202 exit(0);
203 }
204 else if (charg(argv, "--sname", "-sname", p)) {
205 sname = argv[++p];
206 }
207 else if (charg(argv, "--name", "-name", p)) {
208 name = argv[++p];
209 }
210 else if (charg(argv, "--erlarg", "-erlarg", p)) {
211 sprintf(tbuf, " %s ", argv[++p]);
212 strcat(erlarg, tbuf);
213 }
7871338 @klacke win32 work
klacke authored
214 else {
fdfdd8e @klacke prep for 1.80
klacke authored
215 return help();
7871338 @klacke win32 work
klacke authored
216 }
217 p++;
218 }
219
220 if (winteractive)
fdfdd8e @klacke prep for 1.80
klacke authored
221 sprintf(execString, "werl.exe %s %s ", erlarg, paBuf);
7871338 @klacke win32 work
klacke authored
222 else
fdfdd8e @klacke prep for 1.80
klacke authored
223 sprintf(execString, "erl.exe %s %s ", erlarg, paBuf);
7871338 @klacke win32 work
klacke authored
224
225 if (debug)
226 strcat(execString, " -boot start_sasl -yaws debug ");
fdfdd8e @klacke prep for 1.80
klacke authored
227 if ((interactive == 0 && winteractive == 0) || daemon == 1)
228 strcat(execString, " -detached ");
229
7871338 @klacke win32 work
klacke authored
230 if (conf == NULL)
fdfdd8e @klacke prep for 1.80
klacke authored
231 sprintf(tbuf, " -conf \"%s\\yaws.conf\" ", path);
7871338 @klacke win32 work
klacke authored
232 else
fdfdd8e @klacke prep for 1.80
klacke authored
233 sprintf(tbuf, " -conf \"%s\" ", conf);
234 strcat(execString, tbuf);
7871338 @klacke win32 work
klacke authored
235 strcat(execString, " -run yaws -yaws id default ");
236
fdfdd8e @klacke prep for 1.80
klacke authored
237 if (mnesia != NULL)
238 strcat(execString, mnesia);
239 if (trace != NULL)
240 strcat(execString, trace);
241 if (traceoutput != NULL)
242 strcat(execString, traceoutput);
243
244 if (sname != NULL) {
245 sprintf(tbuf," -sname %s ", sname);
246 strcat(execString, tbuf);
247 } else if (name != NULL) {
248 sprintf(tbuf, " -name %s ", name);
249 strcat(execString, tbuf);
250 }
251 if (runmod != NULL) {
252 sprintf(tbuf, " -runmod %s ", runmod);
253 strcat(execString, tbuf);
254 }
255
256 return runwait(execString);
7871338 @klacke win32 work
klacke authored
257 }
258
259
260
Something went wrong with that request. Please try again.