Re: [systemd-devel] Fwd: With my layer, Systemd not invoking my application at startup

2015-07-04 Thread Vipin Nair
>>OK, so you do not appear to be creating the user or changing ownership
>>in your service?

Right, the purpose of service is totally different.

>> Do you do that inside /opt/test_app itself or somewhere
>>else? If so, please include that information.

We use the yacto project model to build the project and create the final
file system image.
There we have the concept of 'pkg_preinst_' and 'pkg_postinstall' modules
for each service. So the preinst is run on the build machine
and sets up the file system. Postinstall can be either run on the build
machine or on the board during the 1st boot.
On the board, this postinstall modules are run before systemd starts the
systemd enabled services.

As part of postinstall script I am doing the user creation and file
ownership changes.
Inside this post install script module, I am registering with systemd
(using the systemctl enable command)

And the problem I am facing is that, if I run my post install on the build
machine, then systemd is able to invoke my service during the 1st boot,
but if I run my postinstall script on the machine, then systemd is not able
to invoke my service at 1st boot. From invoke, I mean systemd is not at all
starting the service.

>>OK, so "post_install" is not a systemd term. It is meaninless in the
>>upstream project. This is presumably something related to your build
>>system but you likely won't find any support for this via the systemd
>>mailing list. I'd get in touch with your distribution for this.

The post_install is a Yacto related term here. In yacto they do a systemd
package and that is what I am using inside my scripts.
I am not sure whether the problem I am facing is with systemd or Yacto, so
I have mailed the problem in both the mailing groups. But have not received
any response from Yacto group yet.


Thanks
Vipin




On Thu, Jul 2, 2015 at 1:46 PM, Colin Guthrie  wrote:

> Hi,
>
> First of all, please keep the list included in your replies. Other
> people may be able to help.
>
> Vipin Nair wrote on 02/07/15 08:05:
> > Thanks a lot Colin for your valuable inputs.
> >
> > here is my service unit file :
> >
> > +
> > [Unit] Description=McAfee Agent (masvc) [Service] Type=forking
> > ExecStartPre=-/bin/mkdir -p /var/tmp/config_file
> > ExecStartPre=-/bin/chmod 777
> > /var/tmp/config_fileExecStartPre=-/bin/chmod o+t
> > /var/tmp/config_fileExecStart=/opt/test_app start
> > ExecStop=/opt/test_appstop Type=forking TimeoutStartSec=20
> > SendSIGKILL=no [Install] WantedBy=multi-user.target
> > +
>
> My mail client decided to reformat it. Sorry.
>
> So for all your ExecStartPre's there you could replace with a tmpfiles.d
> snippet that defines this. tmpfiles is run very early on boot.
>
> > From you reply , I get a feel you have misunderstand the purpose of my
> > service. My service is meant to serve some other purpose.
> > But for service to run, I have to create a new user and change the owner
> > ship of certain files to the new user.
>
> OK, so you do not appear to be creating the user or changing ownership
> in your service? Do you do that inside /opt/test_app itself or somewhere
> else? If so, please include that information.
>
> > Also during the 1st boot after reboot, I have to run a configuration
> > application which sets up the platform / env for my service to run.
>
> OK, so perhaps this answers my question above. How do you run this
> configuration application?
>
> If it simply creates users then you should look into systemd sysusers
> (see "man 5 sysusers.d") to create the user and systemd tmpfiles (see
> "man 5 tmpfiles.d") to create folders and change ownership of files.
>
> > So creating the new user, changing the file ownership and running the
> > configuration app, I have to do as part of post_install and it is to be
> > run on the target board.
>
> OK, so "post_install" is not a systemd term. It is meaninless in the
> upstream project. This is presumably something related to your build
> system but you likely won't find any support for this via the systemd
> mailing list. I'd get in touch with your distribution for this.
>
> Like I said, the sysusers and tmpfiles infrastructure provided by
> systemd can certainly perform some of what you need for your environment
> setup.
>
> > But with this the systemd, does not start my service during the 1st boot.
>
> When you say "does not start" do you mean it doesn't even try to start
> it? Or it tries and fails because the user is not yet setup?
>
&g

[systemd-devel] Fwd: With my layer, Systemd not invoking my application at startup

2015-06-30 Thread Vipin Nair
Hi All,

I am using the yacto style project and I have  created a layer (my first
layer) and have build it with WindRiver media which uses Systemd for the
startup services.

As per my application need, I have to create a new user on the final image
and change the owner permissions of certain files to the new user.
Since I could not get it done on the build machine, I have written the post
install script such that it gets executed on the  target board during the
1st boot cycle
and from within the post install script I am creating the new user and
changing the file ownership. And this works.

But the only problem I have now is that, even though I register my service
with Systemd at pre-install (or postinstall) section (using the systemctl
enable command)
my service is not getting launched by Systemd during the 1st boot. On
subsequent reboots, it invokes my service at boot up.

As part of debugging I just modified my postinstall script, such that it
gets executed on the board (i.e without the exit 1)  and not executed on
the 1st boot. After that I see that
systemd invokes my service at boot up.  So I wonder if Systemd ignores the
services for which post-install is not invoked at build machine ?

Now I am confused on how to solve this problem.

Only 2 approaches comes to my mind :
1) Run the postinstall on the board only (not on 1st boot)  - But with this
(i.e running the postinstall section on board) I don't see the new user
creation happening and as a result it fails to change the file ownership.

2) Somehow force systemd to invoke my service at startup (even with
postinstall running during 1st boot)  - But I don't know what I have to do
to achieve this.

Here is the brief of my recipe file :
---

DEPENDS += "${@bb.utils.contains('DISTRO_FEATURES', 'systemd',
'systemd-systemctl-native', '', d)}"


do_install() {


#if systemd configured
install -m 0755 -d ${D}/lib/systemd/system
cp ${WORKDIR}/${MA_BIN_DIR}/my_ser.service ${D}/lib/systemd/system/


}

pkg_preinst_${PN}() {



if [  "$IS_SYSTEMD_CONFIGURED" = "yes" ] ; then
systemctl --root=$D enable my_ser.service# Have tried executing it only
on postinstall, but it does not help.
fi


}

pkg_postinst_${PN}() {


if [  "$IS_SYSTEMD_CONFIGURED" = "yes" ] ; then
systemctl --root=$D enable ma.service
fi
 if [ x"$D" = "x" ] ; then
 # Create group and user
groupadd test_grp
useradd -r -s /sbin/nologin -g  test_grp test_usr
 chown test_usr:test_grp /etc/test_folder/*
 if [  "$IS_SYSTEMD_CONFIGURED" = "yes" ] ; then
if [ "$1" == 1 ] || [ "$1" = 2 ] ; then  # only install and upgrade
scenario, not to exeute on 1st boot
systemctl daemon-reload
systemctl start my_ser.service
fi
else
exit 1
fi
}

I am new to the yacto project and the layer approach. So kindly guide me on
how to resolve this issue.

Also if this is not the right group to get help on this issue, please
suggest about the relevant group.

Thanks
Vipin
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel