Service
How to register
/etc/init.d/eclipse-che
와 같이 /etc/init.d
디렉토리에 스크립트 파일을 추가한다. 그리고 chmod 755 eclipse-che
로 실행권한을 추가한다.
if [[ $(which java) == "" ]]; then
JAVA_HOME=/usr/local/jdk/
PATH=$JAVA_HOME/bin:$PATH
fi
CHE_HOME=/usr/local/eclipse-che
CHE_BIN=$CHE_HOME/bin/che.sh
# See how we were called
case "$1" in
start)
echo "Start eclipse-che."
$CHE_BIN start
;;
stop)
echo "Stop eclipse-che."
$CHE_BIN stop
;;
restart)
echo "Restart eclipse-che."
$CHE_BIN start
$CHE_BIN stop
;;
*)
echo "Usage: $0 {start|stop|restart}"
exit 1
esac
exit 0
서비스 등록:
Service 명령어:
Service 상태 조회:
Win32 Service install & uninstall
#pragma comment(lib, "advapi32.lib")
LRESULT InstallService ( TSTR Path, TSTR ServiceName, TSTR DisplayName, DWORD StartType )
{
SC_HANDLE schSCManager = OpenSCManager( NULL, NULL, SC_MANAGER_CREATE_SERVICE);
if ( schSCManager != 0 )
{
SC_HANDLE schService = CreateService(schSCManager, ServiceName.c_str(), DisplayName.c_str(), SERVICE_ALL_ACCESS, SERVICE_WIN32_OWN_PROCESS, StartType, SERVICE_ERROR_NORMAL, Path.c_str(), NULL, NULL, NULL, NULL, NULL);
if ( schService != 0 ) {
CloseServiceHandle(schService);
CloseServiceHandle(schSCManager);
return TRUE;
}
CloseServiceHandle(schSCManager);
}
return FALSE;
}
LRESULT RemoveService ( TSTR Name )
{
SC_HANDLE schSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
if ( schSCManager != 0 )
{
SC_HANDLE schService = OpenService(schSCManager, Name.c_str(), SERVICE_ALL_ACCESS);
if ( schService != 0 ) {
DeleteService(schService);
CloseServiceHandle(schService);
CloseServiceHandle(schSCManager);
return TRUE;
}
CloseServiceHandle(schSCManager);
}
return FALSE;
}
LRESULT StartService ( TSTR Name )
{
SC_HANDLE schSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
if ( schSCManager != 0 )
{
SC_HANDLE schService = OpenService(schSCManager, Name.c_str(), SERVICE_ALL_ACCESS);
if ( schService != 0 )
{
if(StartService(schService, 0, (const TCHAR**)NULL))
{
CloseServiceHandle(schService);
CloseServiceHandle(schSCManager);
return TRUE;
}
CloseServiceHandle(schService);
}
CloseServiceHandle(schSCManager);
}
return FALSE;
}
LRESULT StopService ( TSTR Name )
{
SC_HANDLE schSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
if ( schSCManager != 0 )
{
SC_HANDLE schService = OpenService(schSCManager, Name.c_str(), SERVICE_ALL_ACCESS);
if ( schService != 0 )
{
SERVICE_STATUS status;
if( ControlService(schService, SERVICE_CONTROL_STOP, &status) )
{
CloseServiceHandle(schService);
CloseServiceHandle(schSCManager);
return TRUE;
}
CloseServiceHandle(schService);
}
CloseServiceHandle(schSCManager);
}
return FALSE;
}
어플리케이션을 Windows 서비스에 등록하고, 해제하고, 시작하고, 중지하는 함수들입니다. Administrator 권한이 필요합니다.