<div dir="ltr"><span style="font-size:12.8000001907349px">>>OK, so you do not appear to be creating the user or changing ownership</span><br style="font-size:12.8000001907349px"><span style="font-size:12.8000001907349px">>>in your service? </span><div><span style="font-size:12.8000001907349px"><br></span></div><div><span style="font-size:12.8000001907349px">Right, the purpose of service is totally different. <br></span><div><span style="font-size:12.8000001907349px"><br></span></div><div><span style="font-size:12.8000001907349px">>> Do you do that inside /opt/test_app itself or somewhere</span><br style="font-size:12.8000001907349px"><span style="font-size:12.8000001907349px">>>else? If so, please include that information.</span></div><div><span style="font-size:12.8000001907349px"><br></span></div><div><span style="font-size:12.8000001907349px">We use the yacto project model to build the project and create the final file system image. </span></div><div><span style="font-size:12.8000001907349px">There we have the concept of 'pkg_preinst_' and 'pkg_postinstall' modules for each service. So the preinst is run on the build machine </span></div><div><span style="font-size:12.8000001907349px">and sets up the file system. Postinstall can be either run on the build machine or on the board during the 1st boot. </span></div><div><span style="font-size:12.8000001907349px">On the board, this postinstall modules are run before systemd starts the systemd enabled services. </span></div><div><span style="font-size:12.8000001907349px"><br></span></div><div><span style="font-size:12.8000001907349px">As part of postinstall script I am doing the user creation and file ownership changes. </span></div><div><span style="font-size:12.8000001907349px">Inside this post install script module, I am registering with systemd (using the systemctl enable command)</span></div><div><span style="font-size:12.8000001907349px"><br></span></div><div><span style="font-size:12.8000001907349px">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, </span></div><div><span style="font-size:12.8000001907349px">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 </span></div><div><span style="font-size:12.8000001907349px">starting the service. </span></div><div><br></div><div><span style="font-size:12.8000001907349px">>>OK, so "post_install" is not a systemd term. It is meaninless in the</span><br style="font-size:12.8000001907349px"><span style="font-size:12.8000001907349px">>>upstream project. This is presumably something related to your build</span><br style="font-size:12.8000001907349px"><span style="font-size:12.8000001907349px">>>system but you likely won't find any support for this via the systemd</span><br style="font-size:12.8000001907349px"><span style="font-size:12.8000001907349px">>>mailing list. I'd get in touch with your distribution for this.</span><br style="font-size:12.8000001907349px"></div><div><span style="font-size:12.8000001907349px"><br></span></div><div><span style="font-size:12.8000001907349px">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. </span></div><div><span style="font-size:12.8000001907349px">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 </span></div><div><span style="font-size:12.8000001907349px">any response from Yacto group yet. </span></div><div><span style="font-size:12.8000001907349px"><br></span></div><div><br></div><div><span style="font-size:12.8000001907349px">Thanks</span></div><div><span style="font-size:12.8000001907349px">Vipin</span></div><div><span style="font-size:12.8000001907349px"><br></span><div><span style="font-size:12.8000001907349px"><br></span></div><div><span style="font-size:12.8000001907349px"><br></span></div></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Jul 2, 2015 at 1:46 PM, Colin Guthrie <span dir="ltr"><<a href="mailto:gmane@colin.guthr.ie" target="_blank">gmane@colin.guthr.ie</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi,<br>
<br>
First of all, please keep the list included in your replies. Other<br>
people may be able to help.<br>
<br>
Vipin Nair wrote on 02/07/15 08:05:<br>
<span class="">> Thanks a lot Colin for your valuable inputs.<br>
><br>
> here is my service unit file :<br>
><br>
> +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++<br>
> [Unit] Description=McAfee Agent (masvc) [Service] Type=forking<br>
> ExecStartPre=-/bin/mkdir -p /var/tmp/config_file<br>
> ExecStartPre=-/bin/chmod 777<br>
> /var/tmp/config_fileExecStartPre=-/bin/chmod o+t<br>
> /var/tmp/config_fileExecStart=/opt/test_app start<br>
</span>> ExecStop=/opt/test_appstop Type=forking TimeoutStartSec=20<br>
> SendSIGKILL=no [Install] WantedBy=multi-user.target<br>
> +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++<br>
<br>
My mail client decided to reformat it. Sorry.<br>
<br>
So for all your ExecStartPre's there you could replace with a tmpfiles.d<br>
snippet that defines this. tmpfiles is run very early on boot.<br>
<span class=""><br>
> From you reply , I get a feel you have misunderstand the purpose of my<br>
> service. My service is meant to serve some other purpose.<br>
> But for service to run, I have to create a new user and change the owner<br>
> ship of certain files to the new user.<br>
<br>
</span>OK, so you do not appear to be creating the user or changing ownership<br>
in your service? Do you do that inside /opt/test_app itself or somewhere<br>
else? If so, please include that information.<br>
<span class=""><br>
> Also during the 1st boot after reboot, I have to run a configuration<br>
> application which sets up the platform / env for my service to run.<br>
<br>
</span>OK, so perhaps this answers my question above. How do you run this<br>
configuration application?<br>
<br>
If it simply creates users then you should look into systemd sysusers<br>
(see "man 5 sysusers.d") to create the user and systemd tmpfiles (see<br>
"man 5 tmpfiles.d") to create folders and change ownership of files.<br>
<span class=""><br>
> So creating the new user, changing the file ownership and running the<br>
> configuration app, I have to do as part of post_install and it is to be<br>
> run on the target board.<br>
<br>
</span>OK, so "post_install" is not a systemd term. It is meaninless in the<br>
upstream project. This is presumably something related to your build<br>
system but you likely won't find any support for this via the systemd<br>
mailing list. I'd get in touch with your distribution for this.<br>
<br>
Like I said, the sysusers and tmpfiles infrastructure provided by<br>
systemd can certainly perform some of what you need for your environment<br>
setup.<br>
<span class=""><br>
> But with this the systemd, does not start my service during the 1st boot.<br>
<br>
</span>When you say "does not start" do you mean it doesn't even try to start<br>
it? Or it tries and fails because the user is not yet setup?<br>
<span class=""><br>
> If I just run the post install on the build machine (commenting out the<br>
> commands which are suppose to fail) and the then use the image, I see<br>
> that systemd does invoke my service during the 1st boot.<br>
<br>
</span>Again "post install" is not a systemd upstream thing. This is part of<br>
your build system and you should seek help from them for this.<br>
<span class=""><br>
<br>
<br>
> Does systemd waits for the post-install to be finished before<br>
> registering the services ?<br>
<br>
</span>systemd has no concept of "post-install". It does have a first boot and<br>
it does have a way of bootstrapping itself after factory reset (i.e. the<br>
removal of /etc and /var). These capabilities of systemd might be able<br>
to completely replace your post-install process. See the various blog<br>
posts about systemd and "Factory reset" to see if you think this could<br>
help you.<br>
<br>
HTHs<br>
<br>
Col<br>
<span class=""><br>
> If I have to register with systemd after the post-install is run what<br>
> more I have to do ?<br>
><br>
> Waiting for your inputs.<br>
><br>
> Kindly let me know if you need any other information from end.<br>
><br>
> Thanks<br>
> Vipin<br>
><br>
><br>
><br>
><br>
><br>
><br>
><br>
> On Wed, Jul 1, 2015 at 1:41 PM, Colin Guthrie <<a href="mailto:colin@mageia.org">colin@mageia.org</a><br>
</span><div><div class="h5">> <mailto:<a href="mailto:colin@mageia.org">colin@mageia.org</a>>> wrote:<br>
><br>
> Vipin Nair wrote on 01/07/15 07:00:<br>
> ><br>
> ><br>
> > Hi All,<br>
> ><br>
> > I am using the yacto style project and I have created a layer (my first<br>
> > layer) and have build it with WindRiver media which uses Systemd for the<br>
> > startup services.<br>
> ><br>
> > As per my application need, I have to create a new user on the final<br>
> > image and change the owner permissions of certain files to the new user.<br>
> > Since I could not get it done on the build machine, I have written the<br>
> > post install script such that it gets executed on the target board<br>
> > during the 1st boot cycle<br>
> > and from within the post install script I am creating the new user and<br>
> > changing the file ownership. And this works.<br>
> ><br>
> > But the only problem I have now is that, even though I register my<br>
> > service with Systemd at pre-install (or postinstall) section (using the<br>
> > systemctl enable command)<br>
> > my service is not getting launched by Systemd during the 1st boot. On<br>
> > subsequent reboots, it invokes my service at boot up.<br>
><br>
><br>
> It's hard to say without seeing your actual service (specifically it's<br>
> [Install] section) as otherwise we cannot tell what data systemctl<br>
> enable has to work with.<br>
><br>
> However, from the description of your problem I think you're likely<br>
> trying to solve it the wrong way.<br>
><br>
> systemd comes with two concepts to do what you want. sysusers is a<br>
> mechanism to initialise system users and can be confirured to run on<br>
> first boot. It will create your user for you.<br>
><br>
> tmpfiles can create and change ownership of files and directories. It<br>
> runs on every boot.<br>
><br>
> Dropping in the appropriate configuration snippet for both might be<br>
> sufficient for your needs and is likely cleaner than using a service.<br>
><br>
> Hope this helps.<br>
><br>
> Col<br>
><br>
><br>
> --<br>
><br>
> Colin Guthrie<br>
</div></div>> colin(at)<a href="http://mageia.org" rel="noreferrer" target="_blank">mageia.org</a> <<a href="http://mageia.org" rel="noreferrer" target="_blank">http://mageia.org</a>><br>
<span class="im HOEnZb">> <a href="http://colin.guthr.ie/" rel="noreferrer" target="_blank">http://colin.guthr.ie/</a><br>
><br>
> Day Job:<br>
> Tribalogic Limited <a href="http://www.tribalogic.net/" rel="noreferrer" target="_blank">http://www.tribalogic.net/</a><br>
> Open Source:<br>
> Mageia Contributor <a href="http://www.mageia.org/" rel="noreferrer" target="_blank">http://www.mageia.org/</a><br>
> PulseAudio Hacker <a href="http://www.pulseaudio.org/" rel="noreferrer" target="_blank">http://www.pulseaudio.org/</a><br>
> Trac Hacker <a href="http://trac.edgewall.org/" rel="noreferrer" target="_blank">http://trac.edgewall.org/</a><br>
><br>
><br>
<br>
<br>
</span><span class="HOEnZb"><font color="#888888">--<br>
<br>
Colin Guthrie<br>
gmane(at)<a href="http://colin.guthr.ie" rel="noreferrer" target="_blank">colin.guthr.ie</a><br>
</font></span><div class="HOEnZb"><div class="h5"><a href="http://colin.guthr.ie/" rel="noreferrer" target="_blank">http://colin.guthr.ie/</a><br>
<br>
Day Job:<br>
Tribalogic Limited <a href="http://www.tribalogic.net/" rel="noreferrer" target="_blank">http://www.tribalogic.net/</a><br>
Open Source:<br>
Mageia Contributor <a href="http://www.mageia.org/" rel="noreferrer" target="_blank">http://www.mageia.org/</a><br>
PulseAudio Hacker <a href="http://www.pulseaudio.org/" rel="noreferrer" target="_blank">http://www.pulseaudio.org/</a><br>
Trac Hacker <a href="http://trac.edgewall.org/" rel="noreferrer" target="_blank">http://trac.edgewall.org/</a><br>
</div></div></blockquote></div><br></div>