add installer.sh
git-svn-id: file:///raid/svn-personal/tewi/trunk@62 8739d7e6-ffea-ec47-b151-bdff447c6205
This commit is contained in:
parent
88f3bf7750
commit
e43e5b1c69
|
@ -4,5 +4,6 @@
|
||||||
#define __CM_LOG_H__
|
#define __CM_LOG_H__
|
||||||
|
|
||||||
void cm_log(const char* name, const char* log, ...);
|
void cm_log(const char* name, const char* log, ...);
|
||||||
|
void cm_force_log(const char* log);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
14
Common/log.c
14
Common/log.c
|
@ -4,16 +4,28 @@
|
||||||
|
|
||||||
#include "cm_string.h"
|
#include "cm_string.h"
|
||||||
|
|
||||||
|
#include <time.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
|
|
||||||
|
FILE* logfile;
|
||||||
|
|
||||||
bool cm_do_log = false;
|
bool cm_do_log = false;
|
||||||
|
|
||||||
#define LOGNAME_LENGTH 12
|
#define LOGNAME_LENGTH 12
|
||||||
|
|
||||||
|
void cm_force_log(const char* log) {
|
||||||
|
time_t t = time(NULL);
|
||||||
|
struct tm* tm = localtime(&t);
|
||||||
|
char date[513];
|
||||||
|
strftime(date, 512, "%a %b %d %H:%M:%S %Z %Y", tm);
|
||||||
|
fprintf(logfile, "[%s] %s\n", date, log);
|
||||||
|
fflush(logfile);
|
||||||
|
}
|
||||||
|
|
||||||
void cm_log(const char* name, const char* log, ...) {
|
void cm_log(const char* name, const char* log, ...) {
|
||||||
if(!cm_do_log) return;
|
if(!cm_do_log) return;
|
||||||
va_list args;
|
va_list args;
|
||||||
|
@ -56,7 +68,7 @@ void cm_log(const char* name, const char* log, ...) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fprintf(stderr, "%s %s\n", namebuf, result);
|
fprintf(logfile, "%s %s\n", namebuf, result);
|
||||||
va_end(args);
|
va_end(args);
|
||||||
|
|
||||||
free(result);
|
free(result);
|
||||||
|
|
|
@ -14,4 +14,4 @@ all: mod_cgi$(LIB)
|
||||||
$(CC) $(CFLAGS) -c -o $@ $<
|
$(CC) $(CFLAGS) -c -o $@ $<
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -f *.o *.so *.a
|
rm -f *.o *.so *.a *.dll
|
||||||
|
|
13
Platform/win32-service.mk
Normal file
13
Platform/win32-service.mk
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
# $Id$
|
||||||
|
|
||||||
|
PREFIX = C:/Tewi
|
||||||
|
|
||||||
|
CC = i686-w64-mingw32-gcc
|
||||||
|
AR = i686-w64-mingw32-ar
|
||||||
|
WINDRES = i686-w64-mingw32-windres
|
||||||
|
CFLAGS = -g -std=c99 -DPREFIX=\"$(PREFIX)\" -I $(PWD)/Common -fPIC -DSERVICE -mwindows
|
||||||
|
LDFLAGS = -mwindows
|
||||||
|
LIBS = -lws2_32
|
||||||
|
EXEC = .exe
|
||||||
|
LIB = .dll
|
||||||
|
PREOBJS = tewi.res
|
|
@ -11,4 +11,3 @@ LIBS = -lws2_32
|
||||||
EXEC = .exe
|
EXEC = .exe
|
||||||
LIB = .dll
|
LIB = .dll
|
||||||
PREOBJS = tewi.res
|
PREOBJS = tewi.res
|
||||||
INSTALLER = install.exe
|
|
||||||
|
|
13
Platform/win64-service.mk
Normal file
13
Platform/win64-service.mk
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
# $Id$
|
||||||
|
|
||||||
|
PREFIX = C:/Tewi
|
||||||
|
|
||||||
|
CC = x86_64-w64-mingw32-gcc
|
||||||
|
AR = x86_64-w64-mingw32-ar
|
||||||
|
WINDRES = x86_64-w64-mingw32-windres
|
||||||
|
CFLAGS = -g -std=c99 -DPREFIX=\"$(PREFIX)\" -I $(PWD)/Common -fPIC -mwindows
|
||||||
|
LDFLAGS = -mwindows
|
||||||
|
LIBS = -lws2_32
|
||||||
|
EXEC = .exe
|
||||||
|
LIB = .dll
|
||||||
|
PREOBJS = tewi.res
|
|
@ -11,4 +11,3 @@ LIBS = -lws2_32
|
||||||
EXEC = .exe
|
EXEC = .exe
|
||||||
LIB = .dll
|
LIB = .dll
|
||||||
PREOBJS = tewi.res
|
PREOBJS = tewi.res
|
||||||
INSTALLER = install.exe
|
|
||||||
|
|
|
@ -7,10 +7,7 @@ include $(PWD)/Platform/$(PLATFORM).mk
|
||||||
|
|
||||||
OBJS = version.o main.o config.o server.o http.o module.o strptime.o $(EXTOBJS) $(PREOBJS)
|
OBJS = version.o main.o config.o server.o http.o module.o strptime.o $(EXTOBJS) $(PREOBJS)
|
||||||
|
|
||||||
all: tewi$(EXEC) $(INSTALLER)
|
all: tewi$(EXEC)
|
||||||
|
|
||||||
install.exe: tewi$(EXEC) install.nsi
|
|
||||||
makensis install.nsi
|
|
||||||
|
|
||||||
tewi$(EXEC): $(OBJS) ../Common/common.a
|
tewi$(EXEC): $(OBJS) ../Common/common.a
|
||||||
$(CC) $(LDFLAGS) $(EXTLDFLAGS) -o $@ $(OBJS) $(EXTLIBS) $(LIBS) ../Common/common.a
|
$(CC) $(LDFLAGS) $(EXTLDFLAGS) -o $@ $(OBJS) $(EXTLIBS) $(LIBS) ../Common/common.a
|
||||||
|
|
|
@ -5,7 +5,12 @@ OutFile "install.exe"
|
||||||
InstallDir "C:\Tewi"
|
InstallDir "C:\Tewi"
|
||||||
Icon "tewi.ico"
|
Icon "tewi.ico"
|
||||||
LicenseData ../LICENSE
|
LicenseData ../LICENSE
|
||||||
|
|
||||||
|
!include "LogicLib.nsh"
|
||||||
|
!include "Sections.nsh"
|
||||||
|
|
||||||
Page license
|
Page license
|
||||||
|
Page components
|
||||||
Page instfiles
|
Page instfiles
|
||||||
UninstPage uninstConfirm
|
UninstPage uninstConfirm
|
||||||
UninstPage instfiles
|
UninstPage instfiles
|
||||||
|
@ -17,8 +22,6 @@ Section
|
||||||
CreateDirectory "$INSTDIR\bin"
|
CreateDirectory "$INSTDIR\bin"
|
||||||
SetOutPath "$INSTDIR"
|
SetOutPath "$INSTDIR"
|
||||||
File /oname=LICENSE.txt "../LICENSE"
|
File /oname=LICENSE.txt "../LICENSE"
|
||||||
SetOutPath "$INSTDIR\bin"
|
|
||||||
File "tewi.exe"
|
|
||||||
SetOutPath "$INSTDIR\modules"
|
SetOutPath "$INSTDIR\modules"
|
||||||
File "../Module/*.dll"
|
File "../Module/*.dll"
|
||||||
SetOutPath "$INSTDIR\etc"
|
SetOutPath "$INSTDIR\etc"
|
||||||
|
@ -42,7 +45,64 @@ Section
|
||||||
WriteUninstaller "$INSTDIR\uninstall.exe"
|
WriteUninstaller "$INSTDIR\uninstall.exe"
|
||||||
SectionEnd
|
SectionEnd
|
||||||
|
|
||||||
|
Section "Install the executable only" SEL_EXEC
|
||||||
|
SetOutPath "$INSTDIR\bin"
|
||||||
|
File "../tewi.exe"
|
||||||
|
WriteINIStr $INSTDIR\install.ini uninstall service false
|
||||||
|
SectionEnd
|
||||||
|
|
||||||
|
Section /o "Install the service too (NT-only)" SEL_SERVICE
|
||||||
|
WriteINIStr $INSTDIR\install.ini uninstall service true
|
||||||
|
FileOpen $9 $INSTDIR\install.bat w
|
||||||
|
FileWrite $9 '"$SYSDIR\sc.exe" stop "TewiHTTPd"$\r$\n'
|
||||||
|
FileClose $9
|
||||||
|
nsExec::Exec '"$INSTDIR\install.bat"'
|
||||||
|
Pop $0
|
||||||
|
DetailPrint "Waiting for 1s so service can stop..."
|
||||||
|
Sleep 1000
|
||||||
|
CreateDirectory "$INSTDIR\logs"
|
||||||
|
SetOutPath "$INSTDIR\bin"
|
||||||
|
File "../tewi.exe"
|
||||||
|
File /oname=tewisrv.exe "../tewi-service.exe"
|
||||||
|
FileOpen $9 $INSTDIR\install.bat w
|
||||||
|
FileWrite $9 '"$SYSDIR\sc.exe" delete "TewiHTTPd"$\r$\n'
|
||||||
|
FileWrite $9 '"$SYSDIR\sc.exe" create "TewiHTTPd" DisplayName= "Tewi HTTPd" binpath= "$INSTDIR\bin\tewisrv.exe" start= "auto"$\r$\n'
|
||||||
|
FileWrite $9 '"$SYSDIR\sc.exe" start "TewiHTTPd"$\r$\n'
|
||||||
|
FileClose $9
|
||||||
|
nsExec::Exec '"$INSTDIR\install.bat"'
|
||||||
|
Pop $0
|
||||||
|
Delete $INSTDIR\install.bat
|
||||||
|
SectionEnd
|
||||||
|
|
||||||
|
Function .onInit
|
||||||
|
StrCpy $1 ${SEL_EXEC}
|
||||||
|
FunctionEnd
|
||||||
|
|
||||||
|
Function .onSelChange
|
||||||
|
!insertmacro StartRadioButtons $1
|
||||||
|
!insertmacro RadioButton ${SEL_EXEC}
|
||||||
|
!insertmacro RadioButton ${SEL_SERVICE}
|
||||||
|
!insertmacro EndRadioButtons
|
||||||
|
FunctionEnd
|
||||||
|
|
||||||
Section "Uninstall"
|
Section "Uninstall"
|
||||||
|
ReadINIStr $8 $INSTDIR\install.ini uninstall service
|
||||||
|
${If} $8 == "true"
|
||||||
|
FileOpen $9 $INSTDIR\uninstall.bat w
|
||||||
|
FileWrite $9 '"$SYSDIR\sc.exe" stop "TewiHTTPd"$\r$\n'
|
||||||
|
FileClose $9
|
||||||
|
nsExec::Exec '"$INSTDIR\uninstall.bat"'
|
||||||
|
Pop $0
|
||||||
|
FileOpen $9 $INSTDIR\uninstall.bat w
|
||||||
|
DetailPrint "Waiting for 1s so service can stop..."
|
||||||
|
Sleep 1000
|
||||||
|
FileWrite $9 '"$SYSDIR\sc.exe" delete "TewiHTTPd"$\r$\n'
|
||||||
|
FileClose $9
|
||||||
|
nsExec::Exec '"$INSTDIR\uninstall.bat"'
|
||||||
|
Pop $0
|
||||||
|
Delete $INSTDIR\uninstall.bat
|
||||||
|
${EndIf}
|
||||||
|
|
||||||
RMDir /r "$INSTDIR"
|
RMDir /r "$INSTDIR"
|
||||||
RMDir /r "$SMPROGRAMS\Tewi HTTPd"
|
RMDir /r "$SMPROGRAMS\Tewi HTTPd"
|
||||||
|
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <cm_log.h>
|
#include <cm_log.h>
|
||||||
|
#include <cm_string.h>
|
||||||
|
|
||||||
#include "tw_config.h"
|
#include "tw_config.h"
|
||||||
#include "tw_server.h"
|
#include "tw_server.h"
|
||||||
|
@ -25,12 +26,71 @@
|
||||||
|
|
||||||
extern bool cm_do_log;
|
extern bool cm_do_log;
|
||||||
extern struct tw_config config;
|
extern struct tw_config config;
|
||||||
|
extern FILE* logfile;
|
||||||
|
|
||||||
char tw_server[2048];
|
char tw_server[2048];
|
||||||
|
|
||||||
|
int startup(int argc, char** argv);
|
||||||
|
|
||||||
|
#ifdef SERVICE
|
||||||
|
SERVICE_STATUS status;
|
||||||
|
SERVICE_STATUS_HANDLE status_handle;
|
||||||
|
|
||||||
|
void WINAPI servhandler(DWORD control){
|
||||||
|
switch(control){
|
||||||
|
case SERVICE_CONTROL_STOP:
|
||||||
|
case SERVICE_CONTROL_SHUTDOWN:
|
||||||
|
status.dwCurrentState = SERVICE_STOP_PENDING;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
SetServiceStatus(status_handle, &status);
|
||||||
|
}
|
||||||
|
|
||||||
|
void WINAPI servmain(DWORD argc, LPSTR* argv){
|
||||||
|
logfile = fopen(PREFIX "/logs/tewi.log", "a");
|
||||||
|
if(logfile == NULL) logfile = stderr;
|
||||||
|
status.dwServiceType = SERVICE_WIN32_OWN_PROCESS;
|
||||||
|
status.dwCurrentState = SERVICE_START_PENDING;
|
||||||
|
status.dwControlsAccepted = SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_SHUTDOWN;
|
||||||
|
status.dwWin32ExitCode = NO_ERROR;
|
||||||
|
status.dwServiceSpecificExitCode = 0;
|
||||||
|
status.dwCheckPoint = 0;
|
||||||
|
status.dwWaitHint = 0;
|
||||||
|
status_handle = RegisterServiceCtrlHandler("Tewi HTTPd", servhandler);
|
||||||
|
if(status_handle == NULL) return;
|
||||||
|
if(SetServiceStatus(status_handle, &status) == 0) return;
|
||||||
|
int st = startup(argc, argv);
|
||||||
|
if(st != -1){
|
||||||
|
status.dwWin32ExitCode = NO_ERROR;
|
||||||
|
status.dwServiceSpecificExitCode = st;
|
||||||
|
status.dwCurrentState = SERVICE_STOPPED;
|
||||||
|
SetServiceStatus(status_handle, &status);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
status.dwCurrentState = SERVICE_RUNNING;
|
||||||
|
SetServiceStatus(status_handle, &status);
|
||||||
|
tw_server_loop();
|
||||||
|
status.dwCurrentState = SERVICE_STOPPED;
|
||||||
|
SetServiceStatus(status_handle, &status);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
int main(int argc, char** argv) {
|
int main(int argc, char** argv) {
|
||||||
|
logfile = stderr;
|
||||||
|
#ifdef SERVICE
|
||||||
|
SERVICE_TABLE_ENTRY table[] = {{"Tewi HTTPd", servmain}, {NULL, NULL}};
|
||||||
|
StartServiceCtrlDispatcher(table);
|
||||||
|
#else
|
||||||
|
int st = startup(argc, argv);
|
||||||
|
if(st != -1) return st;
|
||||||
|
tw_server_loop();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
int startup(int argc, char** argv){
|
||||||
int i;
|
int i;
|
||||||
const char* confpath = PREFIX "/etc/tewi.conf";
|
const char* confpath = PREFIX "/etc/tewi.conf";
|
||||||
|
if(argv != NULL){
|
||||||
for(i = 1; i < argc; i++) {
|
for(i = 1; i < argc; i++) {
|
||||||
if(argv[i][0] == '-') {
|
if(argv[i][0] == '-') {
|
||||||
if(strcmp(argv[i], "--verbose") == 0 || strcmp(argv[i], "-v") == 0) {
|
if(strcmp(argv[i], "--verbose") == 0 || strcmp(argv[i], "-v") == 0) {
|
||||||
|
@ -67,6 +127,7 @@ int main(int argc, char** argv) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
tw_config_init();
|
tw_config_init();
|
||||||
if(tw_config_read(confpath) != 0) {
|
if(tw_config_read(confpath) != 0) {
|
||||||
fprintf(stderr, "Could not read the config\n");
|
fprintf(stderr, "Could not read the config\n");
|
||||||
|
@ -77,11 +138,13 @@ int main(int argc, char** argv) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
sprintf(tw_server, "Tewi/%s (%s)%s", tw_get_version(), tw_get_platform(), config.extension == NULL ? "" : config.extension);
|
sprintf(tw_server, "Tewi/%s (%s)%s", tw_get_version(), tw_get_platform(), config.extension == NULL ? "" : config.extension);
|
||||||
cm_log("Daemon", "Ready, server: %s", tw_server);
|
char* r = cm_strcat(tw_server, " running...");
|
||||||
|
cm_force_log(r);
|
||||||
|
free(r);
|
||||||
#ifndef __MINGW32__
|
#ifndef __MINGW32__
|
||||||
signal(SIGCHLD, SIG_IGN);
|
signal(SIGCHLD, SIG_IGN);
|
||||||
#else
|
#else
|
||||||
SetConsoleTitle(tw_server);
|
SetConsoleTitle(tw_server);
|
||||||
#endif
|
#endif
|
||||||
tw_server_loop();
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,6 +31,7 @@
|
||||||
#ifdef __MINGW32__
|
#ifdef __MINGW32__
|
||||||
#include <winsock2.h>
|
#include <winsock2.h>
|
||||||
#include <process.h>
|
#include <process.h>
|
||||||
|
#include <windows.h>
|
||||||
|
|
||||||
#include "strptime.h"
|
#include "strptime.h"
|
||||||
#else
|
#else
|
||||||
|
@ -696,6 +697,11 @@ cleanup:
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef SERVICE
|
||||||
|
extern SERVICE_STATUS status;
|
||||||
|
extern SERVICE_STATUS_HANDLE status_handle;
|
||||||
|
#endif
|
||||||
|
|
||||||
void tw_server_loop(void) {
|
void tw_server_loop(void) {
|
||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
while(1) {
|
while(1) {
|
||||||
|
@ -709,6 +715,12 @@ void tw_server_loop(void) {
|
||||||
int ret = select(FD_SETSIZE, &fdset, NULL, NULL, &tv);
|
int ret = select(FD_SETSIZE, &fdset, NULL, NULL, &tv);
|
||||||
if(ret == -1) {
|
if(ret == -1) {
|
||||||
break;
|
break;
|
||||||
|
}else if(ret == 0){
|
||||||
|
#ifdef SERVICE
|
||||||
|
if(status.dwCurrentState == SERVICE_STOP_PENDING){
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
} else if(ret > 0) {
|
} else if(ret > 0) {
|
||||||
/* connection */
|
/* connection */
|
||||||
int i;
|
int i;
|
||||||
|
|
19
installer.sh
Executable file
19
installer.sh
Executable file
|
@ -0,0 +1,19 @@
|
||||||
|
#!/bin/sh
|
||||||
|
# $Id$
|
||||||
|
|
||||||
|
fail() {
|
||||||
|
rm -f tewi-service.exe
|
||||||
|
rm -f tewi.exe
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
make clean || fail
|
||||||
|
make PLATFORM=$1 -j4 || fail
|
||||||
|
cp Server/tewi.exe tewi.exe
|
||||||
|
make clean || fail
|
||||||
|
make PLATFORM=$1-service -j4 || fail
|
||||||
|
cp Server/tewi.exe tewi-service.exe
|
||||||
|
cd Server
|
||||||
|
makensis install.nsi
|
||||||
|
rm -f tewi.exe tewi-service.exe
|
||||||
|
cd ..
|
Loading…
Reference in New Issue
Block a user