Convert to systemd API
authorDariusz Michaluk <d.michaluk@samsung.com>
Fri, 31 May 2013 13:02:18 +0000 (15:02 +0200)
committerDariusz Michaluk <d.michaluk@samsung.com>
Mon, 15 Jul 2013 09:05:47 +0000 (11:05 +0200)
-enable sd_notify (start-up completion notification),
-remove init scripts,
-build package changes.

Change-Id: Ib9128063855e4371bd69adf1801b2d49d80a69ec

oma-ds [deleted file]
oma-ds-agent.manifest
packaging/oma-ds-agent.spec
src/agent/CMakeLists.txt
src/agent/main/main.c
systemd/oma-ds-agent.service [moved from packaging/oma-ds-agent.service with 83% similarity]

diff --git a/oma-ds b/oma-ds
deleted file mode 100755 (executable)
index 893ebdb..0000000
--- a/oma-ds
+++ /dev/null
@@ -1,73 +0,0 @@
-#!/bin/sh
-
-DESC="OMA DS agent daemon"
-NAME=oma-ds-agent
-DAEMON=/usr/bin/$NAME
-SCRIPTNAME=/etc/init.d/oma-ds
-
-[ -x "$DAEMON" ] || exit 0
-
-do_start() {
-       PID=`pidof $NAME`
-       [ -z "$PID" ] || return 1
-       $DAEMON
-       RETVAL=$?
-       return "$RETVAL"
-}
-
-do_stop() {
-       PID=`pidof $NAME`
-       if [ -n "$PID" ]; then
-               kill $PID
-       fi
-       return 0
-}
-
-prt_res() {
-       RETVAL=$1
-
-       case "$RETVAL" in
-               0|1)
-                       echo "... done."
-                       RETVAL=0
-                       ;;
-               *)
-                       echo "... failed!"
-                       RETVAL=1
-                       ;;
-       esac
-
-       return $RETVAL
-}
-
-case "$1" in
-       start)
-               echo "Starting $DESC" "$NAME"
-               if [ -f /opt/usr/data/oma-ds/.oma-ds-agent-enabled ]; then
-                       do_start
-                       prt_res $?
-               else
-                       echo "don't exist oma-ds-agent enabled file"
-                       prt_res $?
-               fi
-               ;;
-       stop)
-               echo "Stopping $DESC" "$NAME"
-               do_stop
-               prt_res $?
-               ;;
-       restart)
-               echo "Stopping $DESC" "$NAME"
-               do_stop
-               prt_res $?
-               sleep 2
-               echo "Starting $DESC" "$NAME"
-               do_start
-               prt_res $?
-               ;;
-       *)
-               echo "Usage: $SCRIPTNAME {start|stop|restart}" >&2
-               exit 3
-               ;;
-esac
-
index e5d31eb..4aa6386 100755 (executable)
@@ -20,8 +20,9 @@
                <filesystem path="/usr/share/oma-ds-cfg/omads_fw_config.xml" label="oma-ds-agent::cfg"/>
                <filesystem path="/opt/dbspace/.omasyncagent.db" exec_label="oma-ds-agent::db"/>
                <filesystem path="/opt/dbspace/.omasyncagent.db-journal" exec_label="oma-ds-agent::db"/>
-               <filesystem path="/etc/init.d/oma-ds" label="_" exec_label="none"/>
                <filesystem path="/usr/share/dbus-1/services/com.samsung.omadsagent.service" label="_"/>
+               <filesystem path="/usr/lib/systemd/system/oma-ds-agent.service" label="_" exec_label="none" />
+               <filesystem path="/usr/lib/systemd/system/graphical.target.wants/oma-ds-agent.service" label="_" exec_label="none" />
        </assign>
        <request>
                <domain name="oma-ds-agent" />
index be332b3..3bcae04 100755 (executable)
@@ -5,7 +5,7 @@ Release:    1
 Group:      TO_BE/FILLED_IN
 License:    Apache License, Version 2.0
 Source0:    %{name}-%{version}.tar.gz
-Source1:       packaing/oma-ds-agent.service
+
 Requires(post): /sbin/ldconfig
 Requires(postun): /sbin/ldconfig
 BuildRequires:  pkgconfig(glib-2.0)
@@ -21,6 +21,7 @@ BuildRequires:  pkgconfig(dlog)
 BuildRequires:  pkgconfig(aul)
 BuildRequires:  expat-devel
 BuildRequires:  cmake
+BuildRequires: pkgconfig(libsystemd-daemon)
 Requires: sys-assert
 
 
@@ -34,16 +35,13 @@ Group:      TO_BE_FILLED
 %description -n ds-public-plugins
 ds public plugins for sync-agent
 
-
 %prep
 %setup -q
 
-
 %build
 cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix}
 make %{?jobs:-j%jobs}
 
-
 %install
 rm -rf %{buildroot}
 
@@ -56,59 +54,26 @@ sqlite3 %{buildroot}/opt/dbspace/.omasyncagent.db "PRAGMA journal_mode = PERSIST
 
 %make_install
 
-# systemd service script sertup
+# systemd service script startup
 mkdir -p %{buildroot}%{_libdir}/systemd/system/graphical.target.wants
-install -m 0644 %SOURCE1 %{buildroot}%{_libdir}/systemd/system/
 ln -s ../oma-ds-agent.service %{buildroot}%{_libdir}/systemd/system/graphical.target.wants/oma-ds-agent.service
 
 %clean
 rm -rf %{buildroot}
 
-
 %post
 if [ ! -d /opt/dbspace ]
 then
        mkdir /opt/dbspace
 fi
-if [ ! -d /etc/rc.d/rc3.d ]
-then
-       mkdir /etc/rc.d/rc3.d
-fi
-if [ ! -d /etc/rc.d/rc5.d ]
-then
-       mkdir /etc/rc.d/rc5.d
-fi
-
-if [ ! -f /etc/rc.d/rc3.d/S91oma-ds-agent ]
-then
-ln -s /etc/init.d/oma-ds /etc/rc.d/rc3.d/S91oma-ds-agent
-fi
-
-if [ ! -f /etc/rc.d/rc5.d/S91oma-ds-agent ]
-then
-       ln -s /etc/init.d/oma-ds /etc/rc.d/rc5.d/S91oma-ds-agent
-fi
-
-#/etc/init.d/oma-ds start
-
-
-%preun
-/etc/init.d/oma-ds stop
-
 
 %postun
 
 rm -f /tmp/agent_fw_event_omads*
 rm -f /tmp/agent_fw_noti_reply_omads*
-
-rm -f /etc/rc.d/rc3.d/S91oma-ds-agent
-rm -f /etc/rc.d/rc5.d/S91oma-ds-agent
-
 rm -f /opt/dbspace/.omasyncagent.db /opt/dbspace/.omasyncagent.db-journal
-
 rm -rf /usr/share/oma-ds-cfg
 
-
 %files
 %attr(600,root,root) /opt/dbspace/.omasyncagent.db
 %attr(600,root,root) /opt/dbspace/.omasyncagent.db-journal
@@ -120,9 +85,6 @@ rm -rf /usr/share/oma-ds-cfg
 
 /usr/share/oma-ds-cfg/*
 
-%defattr(700,root,root)
-/etc/init.d/oma-ds
-
 %defattr(644,root,root)
 /usr/lib/systemd/system/oma-ds-agent.service
 /usr/lib/systemd/system/graphical.target.wants/oma-ds-agent.service
index 77638be..73aaf3e 100755 (executable)
@@ -24,8 +24,8 @@ pkg_check_modules(LPKGS REQUIRED
                                        dlog
                                        aul
                                        dbus-glib-1
+                                       libsystemd-daemon
                                        )
-
 #############################################
 #
 # Step 2. Set Compile Environment
@@ -74,6 +74,6 @@ INSTALL(DIRECTORY ${CMAKE_SOURCE_DIR}/oma-ds-cfg DESTINATION /usr/share)
 # install oma ds dbus file
 INSTALL(FILES ${CMAKE_SOURCE_DIR}/com.samsung.omadsagent.service DESTINATION /usr/share/dbus-1/services)
 
-# install booting script file
-INSTALL(PROGRAMS ${CMAKE_SOURCE_DIR}/${PROJECT_NAME} DESTINATION /etc/init.d/)
+# install systemd service file
+INSTALL(FILES ${CMAKE_SOURCE_DIR}/systemd/oma-ds-agent.service DESTINATION /usr/lib/systemd/system)
 
index 2e3a730..9badd91 100755 (executable)
@@ -40,7 +40,7 @@ typedef enum {
 #include <stdlib.h>
 #include <unistd.h>
 #include <signal.h>
-
+#include <systemd/sd-daemon.h>
 #include <dbus/dbus-glib.h>
 #include <dbus/dbus.h>
 
@@ -393,6 +393,7 @@ int main(int argc, char *argv[])
        sigemptyset(&sig_act.sa_mask);
        sigaction(SIGTERM, &sig_act, NULL);
 
+       sd_notify(1, "READY=1");
        sync_agent_run_main_loop(0);
 
        if (connection) {
similarity index 83%
rename from packaging/oma-ds-agent.service
rename to systemd/oma-ds-agent.service
index f2ddb4a..6ec3096 100755 (executable)
@@ -3,8 +3,8 @@ Description=OMA DS agent
 After=calendar.service contacts-service.service pushd.service msg-service.service dbus.service
 
 [Service]
-#Type=forking
+Type=notify
 ExecStart=/usr/bin/oma-ds-agent 'booting'
 
 [Install]
-WantedBy=graphical.target
\ No newline at end of file
+WantedBy=graphical.target