Re: [systemd-devel] Emulate two cron tab entries to start/stop service unit natively?
On Fri, Aug 19, 2016 at 11:03 AM, Lennart Poetteringwrote: ... However, systemd > does not support natively to stop services by timer, currently. This > means for the "systemctl stop" part you always have to explicitly > invoke it. Does it make sense to implement this as a feature? And if so, is it scheduled to be so? ___ systemd-devel mailing list systemd-devel@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/systemd-devel
Re: [systemd-devel] Emulate two cron tab entries to start/stop service unit natively?
On Mon, 01.08.16 23:59, John (da_audioph...@yahoo.com) wrote: > Is it possible to use a systemd timer unit to start and stop a > service unit according to set times of the day? In my case, > openvpn.service is a forking type if that matters. I can do this > using cron, but am wondering if/how to do it with systemd natively. > > In cron terms, one could do this like so: > # start at 7 AM > * 7 * * * systemctl start openvpn.service > > > # stop at 5 PM > * 17 * * * systemctl stop openvnp.service > > The syntax of the timer with differential commands (ie start the > service at 7 AM and stop it at 5 PM) isn't clear to me even after > consulting `man systemd.time` and `man systemd.timer`. You can do the exact same thing with timer units, and invoke systemctl start/stop based on time. As timers actviate services you can also simply activate the service drirectly via a timer. However, systemd does not support natively to stop services by timer, currently. This means for the "systemctl stop" part you always have to explicitly invoke it. An alternative is to use RuntimeMaxSec=10h in the service, which means you'd make the service terminate after 10h. In this case the shutdown would be scheduled monotonically however, not by calendar. Lennart -- Lennart Poettering, Red Hat ___ systemd-devel mailing list systemd-devel@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/systemd-devel
Re: [systemd-devel] Emulate two cron tab entries to start/stop service unit natively?
> > From: Kai Krakow <hurikha...@gmail.com> >To: systemd-devel@lists.freedesktop.org >Sent: Tuesday, August 2, 2016 6:38 AM >Subject: Re: [systemd-devel] Emulate two cron tab entries to start/stop >service unit natively? > > >Am Mon, 1 Aug 2016 23:59:13 + (UTC) >schrieb John <da_audioph...@yahoo.com>: > >> Is it possible to use a systemd timer unit to start and stop a >> service unit according to set times of the day? In my case, >> openvpn.service is a forking type if that matters. I can do this >> using cron, but am wondering if/how to do it with systemd natively. >> >> In cron terms, one could do this like so: >> # start at 7 AM >> * 7 * * * systemctl start openvpn.service >> >> >> # stop at 5 PM >> * 17 * * * systemctl stop openvnp.service >> >> The syntax of the timer with differential commands (ie start the >> service at 7 AM and stop it at 5 PM) isn't clear to me even after >> consulting `man systemd.time` and `man systemd.timer`. > >Create to additional services, openvpn-start.service and >openvpn-stop.service, which each require openvpn.service to start or >stop (Wants and Conflicts should work). Those two services should be of >type one-shot, so they start once and quit without error. They contain >no exec lines. > >Now create two timer units, openvpn-{start,stop}.timer with appropriate >time definitions and enable those. All other units shouldn't be enabled. Thank you for the detailed reply! Too bad there isn't a more simplistic solution (ie something native in a single timer unit). ___ systemd-devel mailing list systemd-devel@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/systemd-devel
Re: [systemd-devel] Emulate two cron tab entries to start/stop service unit natively?
Am Mon, 1 Aug 2016 23:59:13 + (UTC) schrieb John: > Is it possible to use a systemd timer unit to start and stop a > service unit according to set times of the day? In my case, > openvpn.service is a forking type if that matters. I can do this > using cron, but am wondering if/how to do it with systemd natively. > > In cron terms, one could do this like so: > # start at 7 AM > * 7 * * * systemctl start openvpn.service > > > # stop at 5 PM > * 17 * * * systemctl stop openvnp.service > > The syntax of the timer with differential commands (ie start the > service at 7 AM and stop it at 5 PM) isn't clear to me even after > consulting `man systemd.time` and `man systemd.timer`. Create to additional services, openvpn-start.service and openvpn-stop.service, which each require openvpn.service to start or stop (Wants and Conflicts should work). Those two services should be of type one-shot, so they start once and quit without error. They contain no exec lines. Now create two timer units, openvpn-{start,stop}.timer with appropriate time definitions and enable those. All other units shouldn't be enabled. -- Regards, Kai Replies to list-only preferred. ___ systemd-devel mailing list systemd-devel@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/systemd-devel
[systemd-devel] Emulate two cron tab entries to start/stop service unit natively?
Is it possible to use a systemd timer unit to start and stop a service unit according to set times of the day? In my case, openvpn.service is a forking type if that matters. I can do this using cron, but am wondering if/how to do it with systemd natively. In cron terms, one could do this like so: # start at 7 AM * 7 * * * systemctl start openvpn.service # stop at 5 PM * 17 * * * systemctl stop openvnp.service The syntax of the timer with differential commands (ie start the service at 7 AM and stop it at 5 PM) isn't clear to me even after consulting `man systemd.time` and `man systemd.timer`. ___ systemd-devel mailing list systemd-devel@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/systemd-devel