Re: [systemd-devel] Zero downtime restart of Web application (Nginx, Puma, JRuby)

2016-07-14 Thread Kai Hendry
On Thu, 14 Jul 2016, at 05:07 PM, David Timothy Strauss wrote:
> Dokku would be about a 5-10 lines of shell script with services running
> in
> systemd.

I would love to see that 10 lines of shell you claimed, but I think you
might be underestimating the fine work that went into Dokku!

Cheers,
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/systemd-devel


Re: [systemd-devel] Problems trying to convert a System-V-Init script to systemd

2016-07-14 Thread Andrei Borzenkov
14.07.2016 15:34, Holger Kiehl пишет:
> Hello,
> 
> I am new to systemd and the maintainer of the file distribution software
> AFD (http://www.dwd.de/AFD) and I am trying to adapt this application
> to systemd. The problem I am unable to solve is that doing a reboot,
> poweroff or halt, all process get a SIGTERM before systemd calls the
> command supplied by ExecStop. If I do a 'systemctl stop afd.service'
> everything works as expected. I have searched the web for a solution
> and have tried all the different service Type=, unit After=/Before=
> combination, but failed so far. I must be doing something obviously
> wrong, but unable to see what and need help please.
> 
> The service/unit file looks as follows:
> 
>[Unit]
>Description=Automatic File Distributor
>After=basic.target
> 

This is redundant - it is default for any standard service

>[Service]
>RemainAfterExit=yes
>Type=oneshot

That's wrong (although it is unrelated to the problem you have). It
means systemd expects ExecStart to run and finish. In your case it
appears to work because you use RemainAfterExit, but if you look more
closely, your service is in state where PID is exited.

>ExecStart=-/etc/init.d/afd start
>ExecStop=-/etc/init.d/afd stop
>KillMode=none

Well, in this case you rely on your service to behave well. You must be
very confident :)

>StandardOutput=syslog+console
>StandardError=syslog+console
> 
>[Install]
>WantedBy=multi-user.target
> 
> /etc/init.d/afd is a shell script that starts one or more instances of

If you start multiple instances, you should consider service template so
each instance can be represented as exactly one systemd service.

> the AFD under different users. The users are configured in /etc/sysconfig/afd
> and are started via the following command: su - $afduser -c " AFD>"

so what most likely happens, is - su establishes new login session; on
shutdown these sessions are cleaned up (concurrently with any running
service - unfortunately, there is no way to express dependency between
user and system systemd instances). Here is where you get your signals.

Check with loginctl after service is started - do you see and extra seesion?

> To speed things up a bit the script forks for each user to start/stop the
> AFD instances. The script /etc/init.d/afd is just initiating thinks, but
> always waits for the command to complete. AFD itself has an init process
> (init_afd) that then starts several other process and monitors them.
> 
> In /etc/init.d/afd I have added the following line in the beginning, before
> it wants to do the shutdown:
> 
>echo "Before: ps -u afd: `ps -u $afduser`" >> /var/log/afd.log
> 
> And this then shows the following:
> 
>Before: ps -u afd:   PID TTY  TIME CMD
> 1258 ?00:00:00 init_afd
> 1260 ?00:00:00 system_log 
> 1261 ?00:00:00 event_log 
> 1262 ?00:00:00 receive_log 
> 1263 ?00:00:00 transfer_log 
> 1264 ?00:00:00 trans_db_log 
> 1265 ?00:00:00 archive_watch 
> 1266 ?00:00:00 input_log 
> 1267 ?00:00:00 output_log 
> 1268 ?00:00:00 delete_log 
> 1269 ?00:00:00 production_log 
> 1270 ?00:00:00 distribution_lo 
> 1271 ?00:00:00 amg 
> 1272 ?00:00:00 aldad 
> 1287 ?00:00:00 afd_stat 
> 1288 ?00:00:00 fd 
> 1289 ?00:00:00 dir_check 
> 
> All the process have received a SIGTERM before (or during the execution)
> of the script.
> 
> Any idea what I am doing wrong,

Much :)

> or what else I can try to do a proper
> shutdown of this application under systemd?
>

Use native systemd unit, do not use init scripts. Use User= to
impersonate user, use Type=forking and PIDFile= to proper synchronize
service startup, use templates to run multiple instances.
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/systemd-devel


[systemd-devel] Problems trying to convert a System-V-Init script to systemd

2016-07-14 Thread Holger Kiehl
Hello,

I am new to systemd and the maintainer of the file distribution software
AFD (http://www.dwd.de/AFD) and I am trying to adapt this application
to systemd. The problem I am unable to solve is that doing a reboot,
poweroff or halt, all process get a SIGTERM before systemd calls the
command supplied by ExecStop. If I do a 'systemctl stop afd.service'
everything works as expected. I have searched the web for a solution
and have tried all the different service Type=, unit After=/Before=
combination, but failed so far. I must be doing something obviously
wrong, but unable to see what and need help please.

The service/unit file looks as follows:

   [Unit]
   Description=Automatic File Distributor
   After=basic.target

   [Service]
   RemainAfterExit=yes
   Type=oneshot
   ExecStart=-/etc/init.d/afd start
   ExecStop=-/etc/init.d/afd stop
   KillMode=none
   StandardOutput=syslog+console
   StandardError=syslog+console

   [Install]
   WantedBy=multi-user.target

/etc/init.d/afd is a shell script that starts one or more instances of
the AFD under different users. The users are configured in /etc/sysconfig/afd
and are started via the following command: su - $afduser -c ""
To speed things up a bit the script forks for each user to start/stop the
AFD instances. The script /etc/init.d/afd is just initiating thinks, but
always waits for the command to complete. AFD itself has an init process
(init_afd) that then starts several other process and monitors them.

In /etc/init.d/afd I have added the following line in the beginning, before
it wants to do the shutdown:

   echo "Before: ps -u afd: `ps -u $afduser`" >> /var/log/afd.log

And this then shows the following:

   Before: ps -u afd:   PID TTY  TIME CMD
1258 ?00:00:00 init_afd
1260 ?00:00:00 system_log 
1261 ?00:00:00 event_log 
1262 ?00:00:00 receive_log 
1263 ?00:00:00 transfer_log 
1264 ?00:00:00 trans_db_log 
1265 ?00:00:00 archive_watch 
1266 ?00:00:00 input_log 
1267 ?00:00:00 output_log 
1268 ?00:00:00 delete_log 
1269 ?00:00:00 production_log 
1270 ?00:00:00 distribution_lo 
1271 ?00:00:00 amg 
1272 ?00:00:00 aldad 
1287 ?00:00:00 afd_stat 
1288 ?00:00:00 fd 
1289 ?00:00:00 dir_check 

All the process have received a SIGTERM before (or during the execution)
of the script.

Any idea what I am doing wrong, or what else I can try to do a proper
shutdown of this application under systemd?

Thanks in advance,
Holger
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/systemd-devel


Re: [systemd-devel] Wishlist: HandleLidSwitchDocked ... when powered?

2016-07-14 Thread Mantas Mikulėnas
On Thu, Jul 14, 2016 at 2:42 PM, Michael Biebl  wrote:

> 2016-07-14 9:28 GMT+02:00 Mantas Mikulėnas :
> > On Thu, Jul 14, 2016 at 5:47 AM, Kai Hendry 
> wrote:
> >>
> >> Hi there,
> >>
> >> I want my T460s machine to suspend on lid close only when it's not
> >> charging off mains.
> >>
> >> I've looked over
> >> https://www.freedesktop.org/software/systemd/man/logind.conf.html &
> >> https://wiki.archlinux.org/index.php/Power_management and I don't see
> >> how this can be achieved.
> >
> >
> > I usually deal with this by running `systemd-inhibit
> > --what=handle-lid-switch ` to prevent the auto-suspend. If you want
> an
> > automatic method, here's some scripting around UPower or udev:
> > https://github.com/grawity/hacks/blob/master/desktop/upower-ac-hold or
> > https://github.com/grawity/hacks/blob/master/system/ac-wait.c
>
> Would that trigger a suspend once you unplug the machine and there is
> a pending request which was inhibited?


For inhibiting handle-lid-switch, yes – logind always tries to suspend if
the lid is closed currently, not just when reacting to lid events.

-- 
Mantas Mikulėnas 
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/systemd-devel


Re: [systemd-devel] Wishlist: HandleLidSwitchDocked ... when powered?

2016-07-14 Thread Michael Biebl
2016-07-14 9:28 GMT+02:00 Mantas Mikulėnas :
> On Thu, Jul 14, 2016 at 5:47 AM, Kai Hendry  wrote:
>>
>> Hi there,
>>
>> I want my T460s machine to suspend on lid close only when it's not
>> charging off mains.
>>
>> I've looked over
>> https://www.freedesktop.org/software/systemd/man/logind.conf.html &
>> https://wiki.archlinux.org/index.php/Power_management and I don't see
>> how this can be achieved.
>
>
> I usually deal with this by running `systemd-inhibit
> --what=handle-lid-switch ` to prevent the auto-suspend. If you want an
> automatic method, here's some scripting around UPower or udev:
> https://github.com/grawity/hacks/blob/master/desktop/upower-ac-hold or
> https://github.com/grawity/hacks/blob/master/system/ac-wait.c

Would that trigger a suspend once you unplug the machine and there is
a pending request which was inhibited?


-- 
Why is it that all of the instruments seeking intelligent life in the
universe are pointed away from Earth?
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/systemd-devel


Re: [systemd-devel] Zero downtime restart of Web application (Nginx, Puma, JRuby)

2016-07-14 Thread David Timothy Strauss
Dokku would be about a 5-10 lines of shell script with services running in
systemd.

On Wed, Jul 13, 2016, 20:41 Kai Hendry  wrote:

> On Sat, 18 Jun 2016, at 07:56 PM, Paul Menzel wrote:
> > Is that possible by just using systemd, or is a load balancer like
> > HAProxy or a special NGINX configuration and service file templates
> > needed?
>
> I'm looking for answers too and the best switcheroo I've found so far is
> http://dokku.viewdocs.io/dokku/deployment/zero-downtime-deploys/ which
> leverages Docker and it's not at all integrated with systemd.
>
> Guess a systemd integrated solution would be leveraging machinectl,
> journalctl and more powerful service control, but I haven't seen an
> orchestrated deployment like that yet. Maybe CoreOS has something, I am
> not sure.
> ___
> systemd-devel mailing list
> systemd-devel@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/systemd-devel
>
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/systemd-devel


Re: [systemd-devel] Wishlist: HandleLidSwitchDocked ... when powered?

2016-07-14 Thread Mantas Mikulėnas
On Thu, Jul 14, 2016 at 5:47 AM, Kai Hendry  wrote:

> Hi there,
>
> I want my T460s machine to suspend on lid close only when it's not
> charging off mains.
>
> I've looked over
> https://www.freedesktop.org/software/systemd/man/logind.conf.html &
> https://wiki.archlinux.org/index.php/Power_management and I don't see
> how this can be achieved.
>

I usually deal with this by running `systemd-inhibit
--what=handle-lid-switch ` to prevent the auto-suspend. If you want an
automatic method, here's some scripting around UPower or udev:
https://github.com/grawity/hacks/blob/master/desktop/upower-ac-hold or
https://github.com/grawity/hacks/blob/master/system/ac-wait.c

-- 
Mantas Mikulėnas 
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/systemd-devel