1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
5 * Copyright (C) 2001-2008, Eduardo Silva P.
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Library General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 #include <sys/types.h>
38 #include "scheduler.h"
53 #if defined(__DATE__) && defined(__TIME__)
54 static const char MONKEY_BUILT
[] = __DATE__
" " __TIME__
;
56 static const char MONKEY_BUILT
[] = "Unknown";
61 printf("* Process ID is %i", getpid());
62 printf("\n* Server socket listening on Port %i", config
->serverport
);
63 printf("\n* %i threads, %i client connections per thread, total %i\n",
64 config
->workers
, config
->worker_capacity
,
65 config
->workers
*config
->worker_capacity
);
71 printf("Monkey HTTP Daemon %s\n",VERSION
);
72 printf("Built : %s\n", MONKEY_BUILT
);
73 printf("Home : http://www.monkey-project.com\n");
79 printf("Usage : monkey [-c directory] [-D] [-v] [-h]\n\n");
80 printf("Available options:\n");
81 printf(" -b\t\trun Monkey in benchmark mode, limits are disabled\n");
82 printf(" -c directory\tspecify directory from configuration files\n");
83 printf(" -D\t\trun Monkey as daemon\n");
84 printf(" -v\t\tshow version number\n");
85 printf(" -h\t\tthis help\n\n");
90 int main(int argc
, char **argv
)
95 config
= mk_mem_malloc(sizeof(struct server_config
));
96 config
->file_config
=0;
99 while ((opt
= getopt(argc
, argv
, "DSvhc:")) != -1)
113 if (strlen(optarg
) != 0) {
114 config
->file_config
=optarg
;
118 printf("Monkey: Invalid option or option needs an argument.\n");
124 if(!config
->file_config
){
125 config
->file_config
=MONKEY_PATH_CONF
;
130 mk_config_start_configure();
133 server_fd
= mk_socket_server(config
->serverport
);
135 /* Workers: logger and clock */
136 mk_worker_spawn((void *)mk_logger_worker_init
);
137 mk_worker_spawn((void *)mk_clock_worker_init
);
139 /* Running Monkey as daemon */
142 mk_utils_set_daemon();
145 /* Register PID of Monkey */
146 mk_logger_register_pid();
149 mk_mem_pointers_init();
151 /* Create thread keys */
152 pthread_key_create(&request_index
, NULL
);
153 pthread_key_create(&epoll_fd
, NULL
);
154 pthread_key_create(&timer
, NULL
);
155 pthread_key_create(&mk_cache_iov_log
, NULL
);
156 pthread_key_create(&mk_cache_iov_header
, NULL
);
157 pthread_key_create(&mk_cache_header_toc
, NULL
);
159 /* Change process owner */
160 mk_user_set_uidgid();
162 mk_config_sanity_check();
164 /* Launch monkey http workers */
165 mk_server_launch_workers();
167 /* Print server details */
170 /* Plugins Stage 10 */
171 mk_plugin_stage_run(MK_PLUGIN_STAGE_10
, NULL
, NULL
);
173 /* Server loop, let's listen for incomming clients */
174 mk_server_loop(server_fd
);