Commit 52157aac9dc289f874f4a4081610b5a940fe3262
1 parent
4538d4f6
Exists in
master
Implementando serviço SystemD
Showing
4 changed files
with
78 additions
and
10 deletions
Show diff stats
Makefile.in
... | ... | @@ -37,6 +37,7 @@ exec_prefix=@exec_prefix@ |
37 | 37 | bindir=@bindir@ |
38 | 38 | sbindir=@sbindir@ |
39 | 39 | libdir=@libdir@ |
40 | +unitdir=@SYSTEMD_SYSTEMUNITDIR@ | |
40 | 41 | |
41 | 42 | BASEDIR=@BASEDIR@ |
42 | 43 | SRCDIR=$(BASEDIR)/.src/$(PACKAGE_TARNAME)-$(PACKAGE_VERSION) |
... | ... | @@ -124,6 +125,12 @@ Release: \ |
124 | 125 | install: \ |
125 | 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 | 134 | bz2: \ |
128 | 135 | $(PACKAGE_TARNAME)-$(PACKAGE_VERSION).tar.bz2 |
129 | 136 | ... | ... |
... | ... | @@ -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 | ... | ... |
configure.ac
... | ... | @@ -234,6 +234,27 @@ AC_SUBST(LIB3270_LIBS) |
234 | 234 | AC_SUBST(LIB3270_CFLAGS) |
235 | 235 | |
236 | 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 | 258 | dnl Check for C++ 2011 support |
238 | 259 | dnl --------------------------------------------------------------------------- |
239 | 260 | AC_DEFUN([AX_CHECK_COMPILE_FLAG], |
... | ... | @@ -336,6 +357,7 @@ dnl Configure which files to generate. |
336 | 357 | dnl --------------------------------------------------------------------------- |
337 | 358 | |
338 | 359 | AC_CONFIG_FILES(Makefile) |
360 | +AC_CONFIG_FILES(conf/systemd.service) | |
339 | 361 | |
340 | 362 | dnl --------------------------------------------------------------------------- |
341 | 363 | dnl Output the generated config.status script. | ... | ... |
src/main.c
... | ... | @@ -30,6 +30,9 @@ |
30 | 30 | * |
31 | 31 | */ |
32 | 32 | |
33 | +#include "private.h" | |
34 | +#include <stdio.h> | |
35 | +#include <stdlib.h> | |
33 | 36 | #include <glib.h> |
34 | 37 | #include <glib-object.h> |
35 | 38 | #include <dbus/dbus.h> |
... | ... | @@ -58,6 +61,12 @@ |
58 | 61 | static DBusGConnection * connection = NULL; |
59 | 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 | 70 | GMainLoop * main_loop = NULL; |
62 | 71 | |
63 | 72 | /*---[ Implement ]----------------------------------------------------------------------------------*/ |
... | ... | @@ -98,6 +107,11 @@ static void g_syslog(const gchar *log_domain,GLogLevelFlags log_level,const gcha |
98 | 107 | *ptr = ' '; |
99 | 108 | } |
100 | 109 | |
110 | +#ifdef DEBUG | |
111 | + printf("%s\n",text); | |
112 | + fflush(stdout); | |
113 | +#endif // DEBUG | |
114 | + | |
101 | 115 | syslog(logtype[f].priority,"%s",text); |
102 | 116 | g_free(text); |
103 | 117 | return; |
... | ... | @@ -105,8 +119,8 @@ static void g_syslog(const gchar *log_domain,GLogLevelFlags log_level,const gcha |
105 | 119 | } |
106 | 120 | |
107 | 121 | #ifdef DEBUG |
108 | - fprintf(stderr,"%s\n",message); | |
109 | - fflush(stderr); | |
122 | + printf("%s\n",message); | |
123 | + fflush(stdout); | |
110 | 124 | #endif // DEBUG |
111 | 125 | |
112 | 126 | syslog(LOG_INFO,"%s %s",log_domain ? log_domain : "", message); |
... | ... | @@ -118,7 +132,7 @@ static gboolean do_idle_check(gpointer dunno) { |
118 | 132 | return TRUE; |
119 | 133 | } |
120 | 134 | |
121 | -static int initialize(void) { | |
135 | +static void initialize() { | |
122 | 136 | |
123 | 137 | GError * error = NULL; |
124 | 138 | guint result; |
... | ... | @@ -126,18 +140,17 @@ static int initialize(void) { |
126 | 140 | connection = dbus_g_bus_get_private(bustype, g_main_context_default(), &error); |
127 | 141 | |
128 | 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 | 144 | g_error_free(error); |
131 | - return -1; | |
145 | + return; | |
132 | 146 | } |
133 | 147 | |
134 | 148 | proxy = dbus_g_proxy_new_for_name(connection,DBUS_SERVICE_DBUS,DBUS_PATH_DBUS,DBUS_INTERFACE_DBUS); |
135 | 149 | |
136 | 150 | org_freedesktop_DBus_request_name(proxy, PW3270_SERVICE_DBUS_SERVICE, DBUS_NAME_FLAG_DO_NOT_QUEUE, &result, &error); |
137 | 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 | 156 | GType object_type = PW3270_TYPE_DBUS; |
... | ... | @@ -147,10 +160,15 @@ static int initialize(void) { |
147 | 160 | |
148 | 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 | 173 | int main(int argc, char *argv[]) { |
156 | 174 | |
... | ... | @@ -162,8 +180,16 @@ int main(int argc, char *argv[]) { |
162 | 180 | initialize(); |
163 | 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 | 193 | g_main_loop_run(main_loop); |
168 | 194 | |
169 | 195 | return 0; | ... | ... |