Browse files

Remove daemon for triggering jobs on a listen TCP port

  • Loading branch information...
1 parent 28d3b5a commit 2f165f784db3e255d6ead39369a55354106800b4 @dreamcat4 committed Sep 14, 2010
Showing with 0 additions and 332 deletions.
  1. +0 −1 .gitignore
  2. +0 −157 ext/Makefile
  3. +0 −14 ext/extconf.rb
  4. +0 −160 ext/launchd-socket-listener-unload.cpp
View
1 .gitignore
@@ -39,6 +39,5 @@ pkg
#*.swp
ext/*.o
-ext/launchd-socket-listener-unload
View
157 ext/Makefile
@@ -1,157 +0,0 @@
-
-SHELL = /bin/sh
-
-#### Start of system configuration section. ####
-
-srcdir = .
-topdir = /opt/rvm/rubies/ree-1.8.7-2010.01/lib/ruby/1.8/i686-darwin10.2.0
-hdrdir = $(topdir)
-VPATH = $(srcdir):$(topdir):$(hdrdir)
-exec_prefix = $(prefix)
-prefix = $(DESTDIR)/opt/rvm/rubies/ree-1.8.7-2010.01
-sharedstatedir = $(prefix)/com
-mandir = $(datarootdir)/man
-psdir = $(docdir)
-oldincludedir = $(DESTDIR)/usr/include
-localedir = $(datarootdir)/locale
-bindir = $(exec_prefix)/bin
-libexecdir = $(exec_prefix)/libexec
-sitedir = $(libdir)/ruby/site_ruby
-htmldir = $(docdir)
-vendorarchdir = $(vendorlibdir)/$(sitearch)
-includedir = $(prefix)/include
-infodir = $(datarootdir)/info
-vendorlibdir = $(vendordir)/$(ruby_version)
-sysconfdir = $(prefix)/etc
-libdir = $(exec_prefix)/lib
-sbindir = $(exec_prefix)/sbin
-rubylibdir = $(libdir)/ruby/$(ruby_version)
-docdir = $(datarootdir)/doc/$(PACKAGE)
-dvidir = $(docdir)
-vendordir = $(libdir)/ruby/vendor_ruby
-datarootdir = $(prefix)/share
-pdfdir = $(docdir)
-archdir = $(rubylibdir)/$(arch)
-sitearchdir = $(sitelibdir)/$(sitearch)
-datadir = $(datarootdir)
-localstatedir = $(prefix)/var
-sitelibdir = $(sitedir)/$(ruby_version)
-
-CC = gcc
-LIBRUBY = $(LIBRUBY_A)
-LIBRUBY_A = lib$(RUBY_SO_NAME)-static.a
-LIBRUBYARG_SHARED =
-LIBRUBYARG_STATIC = -l$(RUBY_SO_NAME)-static
-
-RUBY_EXTCONF_H =
-CFLAGS = -fno-common -g -O2 -pipe -fno-common $(cflags)
-INCFLAGS = -I. -I$(topdir) -I$(hdrdir) -I$(srcdir)
-DEFS =
-CPPFLAGS = -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE $(DEFS) $(cppflags)
-CXXFLAGS = $(CFLAGS)
-ldflags = -L.
-dldflags =
-archflag =
-DLDFLAGS = $(ldflags) $(dldflags) $(archflag)
-LDSHARED = cc -dynamic -undefined suppress -flat_namespace
-AR = ar
-EXEEXT =
-
-RUBY_INSTALL_NAME = ruby
-RUBY_SO_NAME = ruby
-arch = i686-darwin10.2.0
-sitearch = i686-darwin10.2.0
-ruby_version = 1.8
-ruby = /opt/rvm/rubies/ree-1.8.7-2010.01/bin/ruby
-RUBY = $(ruby)
-RM = rm -f
-MAKEDIRS = mkdir -p
-INSTALL = /opt/local/bin/ginstall -c
-INSTALL_PROG = $(INSTALL) -m 0755
-INSTALL_DATA = $(INSTALL) -m 644
-COPY = cp
-
-#### End of system configuration section. ####
-
-preload =
-
-libpath = . $(libdir)
-LIBPATH = -L. -L$(libdir)
-DEFFILE =
-
-CLEANFILES = mkmf.log
-DISTCLEANFILES =
-
-extout =
-extout_prefix =
-target_prefix =
-LOCAL_LIBS =
-LIBS = -ldl -lobjc
-SRCS = launchd-socket-listener-unload.cpp
-OBJS = launchd-socket-listener-unload.o
-TARGET = launchd-socket-listener-unload
-DLLIB = $(TARGET)
-EXTSTATIC =
-STATIC_LIB =
-
-BINDIR = $(bindir)
-RUBYCOMMONDIR = $(sitedir)$(target_prefix)
-RUBYLIBDIR = $(sitelibdir)$(target_prefix)
-RUBYARCHDIR = $(sitearchdir)$(target_prefix)
-
-TARGET_SO = $(DLLIB)
-CLEANLIBS = $(TARGET) $(TARGET).il? $(TARGET).tds $(TARGET).map
-CLEANOBJS = *.o *.a *.s[ol] *.pdb *.exp *.bak
-
-all: $(DLLIB)
-static: $(STATIC_LIB)
-
-clean:
- @-$(RM) $(CLEANLIBS) $(CLEANOBJS) $(CLEANFILES)
-
-distclean: clean
- @-$(RM) Makefile $(RUBY_EXTCONF_H) conftest.* mkmf.log
- @-$(RM) core ruby$(EXEEXT) *~ $(DISTCLEANFILES)
-
-realclean: distclean
-install: install-so install-rb
-
-install-so: $(RUBYARCHDIR)
-install-so: $(RUBYARCHDIR)/$(DLLIB)
-$(RUBYARCHDIR)/$(DLLIB): $(DLLIB)
- $(INSTALL_PROG) $(DLLIB) $(RUBYARCHDIR)
-install-rb: pre-install-rb install-rb-default
-install-rb-default: pre-install-rb-default
-pre-install-rb: Makefile
-pre-install-rb-default: Makefile
-$(RUBYARCHDIR):
- $(MAKEDIRS) $@
-
-site-install: site-install-so site-install-rb
-site-install-so: install-so
-site-install-rb: install-rb
-
-.SUFFIXES: .c .m .cc .cxx .cpp .C .o
-
-.cc.o:
- $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) -c $<
-
-.cxx.o:
- $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) -c $<
-
-.cpp.o:
- $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) -c $<
-
-.C.o:
- $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) -c $<
-
-.c.o:
- $(CC) $(INCFLAGS) $(CPPFLAGS) $(CFLAGS) -c $<
-
-$(DLLIB): $(OBJS) Makefile
- @-$(RM) $@
- $(LDSHARED) -o $@ $(OBJS) $(LIBPATH) $(DLDFLAGS) $(LOCAL_LIBS) $(LIBS)
-
-
-
-$(OBJS): ruby.h defines.h
View
14 ext/extconf.rb
@@ -1,14 +0,0 @@
-#!/usr/bin/env ruby
-
-require 'mkmf'
-create_makefile("launchd-socket-listener-unload")
-
-makefile = File.read("Makefile")
-makefile.gsub!(/-bundle ?/,"")
-makefile.gsub!(/\$\(TARGET\)\.bundle/,"$(TARGET)")
-
-File.open("Makefile","w") do |f|
- f.puts makefile
-end
-
-
View
160 ext/launchd-socket-listener-unload.cpp
@@ -1,160 +0,0 @@
-//
-// launchd-socket-listener-unload.cpp
-// http://fazekasmiklos.blogspot.com/2007/04/howto-unload-launchd-deamon-from-itself.html
-//
-// Instructions by Dreamcat4 (dreamcat4@gmail.com)
-//
-// To compile:
-// $ g++ launchd-socket-listener-unload.cpp -o launchd-socket-listener-unload
-//
-// A small program which unloads the launchd job that started it
-// Use with the below configuration to trigger the real job to load
-//
-// Create a plist file for this daemon called "launchd.myjob.label-loader.plist"
-// Put the listener socket definitions here
-//
-//
-// <key>Program</key>
-// <string>/path/to/launchd-socket-listener-unload</string>
-// <key>ServiceIPC</key>
-// <true/>
-// <key>Sockets</key>
-// <dict>
-// <key>Listeners</key>
-// <dict>
-// <!-- Service name (/etc/services), or a tcp port number -->
-// <!-- or can be anything else launchd supports (udp,etc) -->
-// <key>SockServiceName</key>
-// <string>8080</string>
-// </dict>
-// </dict>
-//
-// You probably already have made a 2nd plist file called "launchd_myjob_label.plist"
-// Add to this file a KeepAlive directive, which depends on the first job not running
-//
-// keep alive -> other job enabled -> false
-//
-// <key>KeepAlive</key>
-// <dict>
-// <key>OtherJobEnabled</key>
-// <dict>
-// <key>launchd.myjob.label-loader</key>
-// <false/>
-// </dict>
-// </dict>
-//
-//
-// This job will then start when the first job is unloaded, which is
-// whenever the first job is triggered by one of the listener sockets
-//
-// Bear in mind,
-// The very first http request / connection attempt will be dropped
-// So a connecting client will have to try again in order to establish
-// a connection to the real job.
-
-#include <stdlib.h>
-#include <errno.h>
-#include <syslog.h>
-
-#include "launch.h"
-
-class LaunchD
-{
-public:
- LaunchD()
- {
- startedWithLaunchD = false;
- me = 0;
- CheckIn();
- }
-
- ~LaunchD()
- {
- if (me) {
- launch_data_free(me);
- }
- }
-
- bool CheckIn(bool allowRunWithoutLaunchd = true)
- {
- launch_data_t msg, resp;
- msg = launch_data_new_string(LAUNCH_KEY_CHECKIN);
- if ((resp = launch_msg(msg)) == NULL) {
- if (allowRunWithoutLaunchd) {
- startedWithLaunchD = false;
- return false;
- }
- syslog(LOG_ERR,"Checkin with launchd failed: %m");
- exit(EXIT_FAILURE);
- }
- launch_data_free(msg);
- if (LAUNCH_DATA_ERRNO == launch_data_get_type(resp)) {
- errno = launch_data_get_errno(resp);
- if (errno == EACCES) {
- syslog(LOG_ERR, "Check-in failed. Did you forget to set"
- "ServiceIPC == true in your plist?");
- } else {
- syslog(LOG_ERR, "Check-in failed: %m");
- }
- exit(EXIT_FAILURE);
- }
- launch_data_t tmp = launch_data_dict_lookup(resp, LAUNCH_JOBKEY_LABEL);
- me = launch_data_copy(tmp);
- if(me)
- {
- syslog(LOG_ERR, "%s triggered\n",job_label());
- }
- startedWithLaunchD = true;
- return true;
- }
-
- const char* job_label()
- {
- return launch_data_get_string(me);
- }
-
- bool Stop()
- {
- if (startedWithLaunchD) {
- launch_data_t resp;
- launch_data_t msg = launch_data_alloc(LAUNCH_DATA_DICTIONARY);
- if (! launch_data_dict_insert(msg,me,LAUNCH_KEY_REMOVEJOB)) {
- syslog(LOG_ERR, "launch_data_dict_insert failed!\n");
- return false;
- }
- if (! launch_data_dict_insert(msg,me,LAUNCH_KEY_STOPJOB)) {
- syslog(LOG_ERR, "launch_data_dict_insert failed!\n");
- return false;
- }
- syslog(LOG_ERR, "%s unloaded\n", job_label());
- resp = launch_msg(msg);
- syslog(LOG_ERR, "%s ...not unloaded. Failure when trying to unload %s.\n", job_label(), job_label());
- if (resp == NULL) {
- syslog(LOG_ERR, "launch_msg() LAUNCH_KEY_STOPJOB failed!\n");
- return false;
- }
- if (LAUNCH_DATA_ERRNO == launch_data_get_type(resp)) {
- errno = launch_data_get_errno(resp);
- if (errno == EACCES) {
- syslog(LOG_ERR, "Stop request failed EACCESS!");
- } else {
- syslog(LOG_ERR, "Check-in failed: %m");
- }
- exit(EXIT_FAILURE);
- }
- launch_data_free(msg);
- }
- return true;
- }
-private:
- bool startedWithLaunchD;
- launch_data_t me;
-};
-
-
-int main()
-{
- LaunchD ld;
- ld.Stop();
-}
-

0 comments on commit 2f165f7

Please sign in to comment.