You are not logged in.

#1 2012-06-20 10:22:33

bernhard_dunkl
Member
Registered: 2012-06-19
Posts: 4

CUPS and systemd: on demand start and stop

Hi,

I am using systemd and I have enabled cups.socket, which comes with the cups package. The cupsd now only gets started when I connect to it (e.g. browsing to localhost:631), but it does not get stopped after all connections have been closed, which I would expect when using it on demand. Are there any additional settings I have to tweak to stop cupsd after the job is done?

The sshd gets started and stopped when using sshd.socket.

Regards,

Bernhard

Offline

#2 2012-06-20 10:33:43

65kid
Member
From: Germany
Registered: 2011-01-26
Posts: 663

Re: CUPS and systemd: on demand start and stop

adding StopWhenUnneeded=yes to the service file may work.
Note however that this will not work as long as you have a (turned on) usb printer connected to the PC. udev automatically starts printer.target when a USB printer is plugged in and stops it when no more usb printer is active. And as long as printer.target is active, cups.service will not stop because it is "WantedBy" printer.target. This is at least how I understand it, may not be completely right on this...

see "man systemd.unit" and https://wiki.archlinux.org/index.php/Sy … it_file.3F

Offline

#3 2012-06-20 11:28:32

bernhard_dunkl
Member
Registered: 2012-06-19
Posts: 4

Re: CUPS and systemd: on demand start and stop

Thanks for your help. It seems that StopWhenUnneeded=yes is too aggressive. When I try to open localhost:631 in a browser cups.service gets stopped multiple times and finally refuses to start:

Jun 20 13:09:20 bernhard-desktop systemd[1]: Service cups.service is not needed anymore. Stopping.
Jun 20 13:09:20 bernhard-desktop systemd[1]: Service cups.service is not needed anymore. Stopping.
Jun 20 13:09:20 bernhard-desktop systemd[1]: Service cups.service is not needed anymore. Stopping.
Jun 20 13:09:20 bernhard-desktop systemd[1]: Service cups.service is not needed anymore. Stopping.
Jun 20 13:09:20 bernhard-desktop systemd[1]: Service cups.service is not needed anymore. Stopping.
Jun 20 13:09:20 bernhard-desktop systemd[1]: Service cups.service is not needed anymore. Stopping.
Jun 20 13:09:20 bernhard-desktop systemd[1]: cups.service start request repeated too quickly, refusing to start.
Jun 20 13:09:20 bernhard-desktop systemd[1]: cups.service start request repeated too quickly, refusing to start.
Jun 20 13:09:20 bernhard-desktop systemd[1]: Unit cups.socket entered failed state.

Offline

#4 2012-06-20 11:38:28

tomegun
Developer
From: France
Registered: 2010-05-28
Posts: 661

Re: CUPS and systemd: on demand start and stop

I don't believe that is how StopWhenUneeded is supposed to work (it shuts down units that are not Required by any other units, which is why it immediately tries to shut down when started by socket activation, nothing requires it).

In general systemd can not know if cups is in use or not, and it should be up to the cups daemon to shut itself down when required as it is the only one who knows (systemd will then tidy up after it and "stop" the service).

That said, you might want to reconsider shutting down cups. If it is inactive, it will not do anything, and eventually be swapped out (if memory is your concern). Shutting it down seems like a waste of resources to me, especially if you might be starting it up again later.

Do you have any specific reason for wanting to shut it down?

Offline

#5 2012-06-20 11:38:54

65kid
Member
From: Germany
Registered: 2011-01-26
Posts: 663

Re: CUPS and systemd: on demand start and stop

hm, so cups.socket starts cups.service, but systemd stops it immediately because no unit actually "Wants" or "Requires" cups.service. As far as I can see this "works" as expected...
Not sure how you could solve this, I guess this is the reason this isn't enabled by default... wink

edit: ignore this, tomegun was faster with a better answer... smile

Last edited by 65kid (2012-06-20 11:40:54)

Offline

#6 2012-06-20 12:43:45

bernhard_dunkl
Member
Registered: 2012-06-19
Posts: 4

Re: CUPS and systemd: on demand start and stop

I am printing only once a month and so cups does not need to run all the time. Starting it on demand works and If there is no setting to stop it, it is no great problem, because it will only run till the next (daily) boot.

Offline

Board footer

Powered by FluxBB