Commit 52157aac9dc289f874f4a4081610b5a940fe3262

Authored by Perry Werneck
1 parent 4538d4f6
Exists in master

Implementando serviço SystemD

@@ -37,6 +37,7 @@ exec_prefix=@exec_prefix@ @@ -37,6 +37,7 @@ exec_prefix=@exec_prefix@
37 bindir=@bindir@ 37 bindir=@bindir@
38 sbindir=@sbindir@ 38 sbindir=@sbindir@
39 libdir=@libdir@ 39 libdir=@libdir@
  40 +unitdir=@SYSTEMD_SYSTEMUNITDIR@
40 41
41 BASEDIR=@BASEDIR@ 42 BASEDIR=@BASEDIR@
42 SRCDIR=$(BASEDIR)/.src/$(PACKAGE_TARNAME)-$(PACKAGE_VERSION) 43 SRCDIR=$(BASEDIR)/.src/$(PACKAGE_TARNAME)-$(PACKAGE_VERSION)
@@ -124,6 +125,12 @@ Release: \ @@ -124,6 +125,12 @@ Release: \
124 install: \ 125 install: \
125 $(BINRLS)/$(PACKAGE_NAME) 126 $(BINRLS)/$(PACKAGE_NAME)
126 127
  128 + @$(MKDIR) $(DESTDIR)/$(sbindir)
  129 + @$(INSTALL_PROGRAM) $(BINRLS)/$(PACKAGE_NAME) $(DESTDIR)/$(sbindir)/$(PACKAGE_NAME)
  130 +
  131 + @$(MKDIR) $(DESTDIR)/$(unitdir)
  132 + @$(INSTALL_DATA) conf/systemd.service $(DESTDIR)/$(unitdir)/$(PACKAGE_NAME).service
  133 +
127 bz2: \ 134 bz2: \
128 $(PACKAGE_TARNAME)-$(PACKAGE_VERSION).tar.bz2 135 $(PACKAGE_TARNAME)-$(PACKAGE_VERSION).tar.bz2
129 136
conf/systemd.service.in 0 → 100644
@@ -0,0 +1,13 @@ @@ -0,0 +1,13 @@
  1 +[Unit]
  2 +Description=@PACKAGE_DESCRIPTION@
  3 +After=syslog.target network.target
  4 +
  5 +[Service]
  6 +ExecStart=/usr/sbin/@PACKAGE_NAME@
  7 +Type=forking
  8 +PIDFile=/var/run/@PACKAGE_NAME@.pid
  9 +KillMode=process
  10 +Restart=on-failure
  11 +
  12 +[Install]
  13 +WantedBy=default.target
@@ -234,6 +234,27 @@ AC_SUBST(LIB3270_LIBS) @@ -234,6 +234,27 @@ AC_SUBST(LIB3270_LIBS)
234 AC_SUBST(LIB3270_CFLAGS) 234 AC_SUBST(LIB3270_CFLAGS)
235 235
236 dnl --------------------------------------------------------------------------- 236 dnl ---------------------------------------------------------------------------
  237 +dnl Check for systemd
  238 +dnl ---------------------------------------------------------------------------
  239 +
  240 +AC_ARG_WITH([systemdsystemunitdir],
  241 + AC_HELP_STRING([--with-systemdsystemunitdir=DIR],
  242 + [path to systemd system unit directory]),
  243 + [path_systemunitdir=${withval}])
  244 +
  245 +
  246 +if test -z "${path_systemunitdir}"; then
  247 + AC_MSG_CHECKING([systemd system unit dir])
  248 + path_systemunitdir="`$PKG_CONFIG --variable=systemdsystemunitdir systemd`"
  249 + if (test -z "${path_systemunitdir}"); then
  250 + AC_MSG_ERROR([systemd system unit directory is required])
  251 + fi
  252 + AC_MSG_RESULT([${path_systemunitdir}])
  253 +fi
  254 +
  255 +AC_SUBST(SYSTEMD_SYSTEMUNITDIR, [${path_systemunitdir}])
  256 +
  257 +dnl ---------------------------------------------------------------------------
237 dnl Check for C++ 2011 support 258 dnl Check for C++ 2011 support
238 dnl --------------------------------------------------------------------------- 259 dnl ---------------------------------------------------------------------------
239 AC_DEFUN([AX_CHECK_COMPILE_FLAG], 260 AC_DEFUN([AX_CHECK_COMPILE_FLAG],
@@ -336,6 +357,7 @@ dnl Configure which files to generate. @@ -336,6 +357,7 @@ dnl Configure which files to generate.
336 dnl --------------------------------------------------------------------------- 357 dnl ---------------------------------------------------------------------------
337 358
338 AC_CONFIG_FILES(Makefile) 359 AC_CONFIG_FILES(Makefile)
  360 +AC_CONFIG_FILES(conf/systemd.service)
339 361
340 dnl --------------------------------------------------------------------------- 362 dnl ---------------------------------------------------------------------------
341 dnl Output the generated config.status script. 363 dnl Output the generated config.status script.
@@ -30,6 +30,9 @@ @@ -30,6 +30,9 @@
30 * 30 *
31 */ 31 */
32 32
  33 +#include "private.h"
  34 +#include <stdio.h>
  35 +#include <stdlib.h>
33 #include <glib.h> 36 #include <glib.h>
34 #include <glib-object.h> 37 #include <glib-object.h>
35 #include <dbus/dbus.h> 38 #include <dbus/dbus.h>
@@ -58,6 +61,12 @@ @@ -58,6 +61,12 @@
58 static DBusGConnection * connection = NULL; 61 static DBusGConnection * connection = NULL;
59 static DBusGProxy * proxy = NULL; 62 static DBusGProxy * proxy = NULL;
60 63
  64 +#ifdef DEBUG
  65 + static gchar * pidfile = PACKAGE_NAME ".pid";
  66 +#else
  67 + static gchar * pidfile = "/var/run/" PACKAGE_NAME ".pid";
  68 +#endif // DEBUG
  69 +
61 GMainLoop * main_loop = NULL; 70 GMainLoop * main_loop = NULL;
62 71
63 /*---[ Implement ]----------------------------------------------------------------------------------*/ 72 /*---[ Implement ]----------------------------------------------------------------------------------*/
@@ -98,6 +107,11 @@ static void g_syslog(const gchar *log_domain,GLogLevelFlags log_level,const gcha @@ -98,6 +107,11 @@ static void g_syslog(const gchar *log_domain,GLogLevelFlags log_level,const gcha
98 *ptr = ' '; 107 *ptr = ' ';
99 } 108 }
100 109
  110 +#ifdef DEBUG
  111 + printf("%s\n",text);
  112 + fflush(stdout);
  113 +#endif // DEBUG
  114 +
101 syslog(logtype[f].priority,"%s",text); 115 syslog(logtype[f].priority,"%s",text);
102 g_free(text); 116 g_free(text);
103 return; 117 return;
@@ -105,8 +119,8 @@ static void g_syslog(const gchar *log_domain,GLogLevelFlags log_level,const gcha @@ -105,8 +119,8 @@ static void g_syslog(const gchar *log_domain,GLogLevelFlags log_level,const gcha
105 } 119 }
106 120
107 #ifdef DEBUG 121 #ifdef DEBUG
108 - fprintf(stderr,"%s\n",message);  
109 - fflush(stderr); 122 + printf("%s\n",message);
  123 + fflush(stdout);
110 #endif // DEBUG 124 #endif // DEBUG
111 125
112 syslog(LOG_INFO,"%s %s",log_domain ? log_domain : "", message); 126 syslog(LOG_INFO,"%s %s",log_domain ? log_domain : "", message);
@@ -118,7 +132,7 @@ static gboolean do_idle_check(gpointer dunno) { @@ -118,7 +132,7 @@ static gboolean do_idle_check(gpointer dunno) {
118 return TRUE; 132 return TRUE;
119 } 133 }
120 134
121 -static int initialize(void) { 135 +static void initialize() {
122 136
123 GError * error = NULL; 137 GError * error = NULL;
124 guint result; 138 guint result;
@@ -126,18 +140,17 @@ static int initialize(void) { @@ -126,18 +140,17 @@ static int initialize(void) {
126 connection = dbus_g_bus_get_private(bustype, g_main_context_default(), &error); 140 connection = dbus_g_bus_get_private(bustype, g_main_context_default(), &error);
127 141
128 if(error) { 142 if(error) {
129 - g_message("Error \"%s\" getting D-Bus connection",error->message); 143 + g_error("Error \"%s\" getting D-Bus connection",error->message);
130 g_error_free(error); 144 g_error_free(error);
131 - return -1; 145 + return;
132 } 146 }
133 147
134 proxy = dbus_g_proxy_new_for_name(connection,DBUS_SERVICE_DBUS,DBUS_PATH_DBUS,DBUS_INTERFACE_DBUS); 148 proxy = dbus_g_proxy_new_for_name(connection,DBUS_SERVICE_DBUS,DBUS_PATH_DBUS,DBUS_INTERFACE_DBUS);
135 149
136 org_freedesktop_DBus_request_name(proxy, PW3270_SERVICE_DBUS_SERVICE, DBUS_NAME_FLAG_DO_NOT_QUEUE, &result, &error); 150 org_freedesktop_DBus_request_name(proxy, PW3270_SERVICE_DBUS_SERVICE, DBUS_NAME_FLAG_DO_NOT_QUEUE, &result, &error);
137 if(error) { 151 if(error) {
138 - g_message("Error \"%s\" getting D-Bus name",error->message);  
139 - g_error_free(error);  
140 - return -1; 152 + g_error("Error \"%s\" getting D-Bus name",error->message);
  153 + return;
141 } 154 }
142 155
143 GType object_type = PW3270_TYPE_DBUS; 156 GType object_type = PW3270_TYPE_DBUS;
@@ -147,10 +160,15 @@ static int initialize(void) { @@ -147,10 +160,15 @@ static int initialize(void) {
147 160
148 g_timeout_add_seconds (1, do_idle_check, NULL); 161 g_timeout_add_seconds (1, do_idle_check, NULL);
149 162
150 - return 0;  
151 } 163 }
152 164
  165 +static void cleanup() {
  166 +
  167 + if(pidfile) {
  168 + remove(pidfile);
  169 + }
153 170
  171 +}
154 172
155 int main(int argc, char *argv[]) { 173 int main(int argc, char *argv[]) {
156 174
@@ -162,8 +180,16 @@ int main(int argc, char *argv[]) { @@ -162,8 +180,16 @@ int main(int argc, char *argv[]) {
162 initialize(); 180 initialize();
163 init_3270(); 181 init_3270();
164 182
165 - main_loop = g_main_loop_new(NULL, FALSE); 183 + atexit(cleanup);
  184 + if(pidfile) {
  185 + FILE * hpid = fopen(pidfile,"w");
  186 + if(hpid) {
  187 + fprintf(hpid,"%u",(unsigned int) getpid());
  188 + fclose(hpid);
  189 + }
  190 + }
166 191
  192 + main_loop = g_main_loop_new(NULL, FALSE);
167 g_main_loop_run(main_loop); 193 g_main_loop_run(main_loop);
168 194
169 return 0; 195 return 0;