You are not logged in.

#1 2016-02-10 06:43:48

Quardah
Member
Registered: 2014-08-26
Posts: 146

custom service not starting

Hello,

This is the first time i made a service for systemd myself, and i can't get it to work hmm

The service is simple; since xmobar fails to refresh itself after waking up the laptop (which i can't find a fix), i wanted to make a service to kill the process everytime the laptop wakes and restart a new one.

Here is the content of my service, located in /usr/lib/systemd/system :

[jape@T420 system]$ cat refreshxmobar.service 
[Unit]
Description=MADEBYJPBD Refresh xmobar script
After=suspend.target
After=hibernate.target

[Service]
Type=oneshot
User=jape
Environment=DISPLAY=:0
ExecStart=/usr/bin/refreshxmobar

[Install]
WantedBy=sleep.target
WantedBy=hibernate.target[jape@T420 system]$ pwd
/etc/systemd/system
[jape@T420 system]$ cat refreshxmobar.service 
[Unit]
Description=MADEBYJPBD Refresh xmobar script
After=suspend.target
After=hibernate.target

[Service]
Type=oneshot
User=jape
Environment=DISPLAY=:0
ExecStart=/usr/bin/refreshxmobar

[Install]
WantedBy=sleep.target
WantedBy=hibernate.target
[jape@T420 system]$ 

Here's the content of /usr/bin/refreshxmobar :

[jape@T420 system]$ cat /usr/bin/refreshxmobar 
#!/bin/sh

if pidof -s xmobar > /dev/null; then
   echo 'present';
   pkill xmobar && xmobar&
else
   echo 'non';
   xmobar&
fi

When trying to enable using

sudo systemctl enable refreshxmobar.service

symlinks are created both for hibernate and sleep.

when starting, it simply kills xmobar, nothing else, and the service does not appear on the list if i use the systemctl command.

What am i doing wrong?

Thanks.


ThinkPad P16s AMD / KDE

Offline

#2 2016-02-10 07:28:57

Docbroke
Member
From: India
Registered: 2015-06-13
Posts: 1,475

Re: custom service not starting

1. you don't need both hibernate.target and sleep.target, only one will do
2. your service is oneshot, so when you start the service it kills xmobar and exit, about restarting xmobar check running your script directly in terminal

I would suggest to make this service simple and enable it rather than starting it, and see what happens on reboot/restart.

Last edited by Docbroke (2016-02-10 07:30:27)

Offline

#3 2016-02-10 08:09:35

Head_on_a_Stick
Member
From: The Wirral
Registered: 2014-02-20
Posts: 9,003
Website

Re: custom service not starting

This won't work anyway, whenever I kill & restart xmobar from the X session the stdin reader doesn't work because the program startup is mediated from the xmonad binary.

It just does this:
2016_02_10_080458_137x19_scrot.png
How are you starting xmobar?

I call it from xmonad.hs: https://github.com/Head-on-a-Stick/conf … nad.hs#L15

My xmobar refreshes just fine after waking from suspend.


Jin, Jîyan, Azadî

Offline

#4 2016-02-10 23:57:19

Quardah
Member
Registered: 2014-08-26
Posts: 146

Re: custom service not starting

Head_on_a_Stick wrote:

This won't work anyway, whenever I kill & restart xmobar from the X session the stdin reader doesn't work because the program startup is mediated from the xmonad binary.

It just does this:
http://s15.postimg.org/4avln8hmf/2016_0 … _scrot.png
How are you starting xmobar?

I call it from xmonad.hs: https://github.com/Head-on-a-Stick/conf … nad.hs#L15

My xmobar refreshes just fine after waking from suspend.


I am not using xmonad. xmobar runs as standalone and it works manually so i guess there is no reason it cannot be automated.


Docbroke wrote:

1. you don't need both hibernate.target and sleep.target, only one will do
2. your service is oneshot, so when you start the service it kills xmobar and exit, about restarting xmobar check running your script directly in terminal

I would suggest to make this service simple and enable it rather than starting it, and see what happens on reboot/restart.

This is what it currently looks like :

[jape@T420 system]$ cat refreshxmobar.service 
[Unit]
Description=MADEBYJPBD Refresh xmobar script
After=sleep.target

[Service]
User=jape
Environment=DISPLAY=:0
ExecStart=/usr/bin/refreshxmobar

[Install]
WantedBy=sleep.target

If i enable the service, it does not appear on my list when i issue the command systemctl.

systemctl status refreshxmobar.service gives me the following (i issued a start command 3 times, all it did was kill my xmobar) :

[jape@T420 system]$ systemctl status refreshxmobar.service 
● refreshxmobar.service - MADEBYJPBD Refresh xmobar script
   Loaded: loaded (/etc/systemd/system/refreshxmobar.service; enabled; vendor preset: disabled)
   Active: inactive (dead)

Feb 10 18:13:22 T420 systemd[1]: Started MADEBYJPBD Refresh xmobar script.
Feb 10 18:23:29 T420 systemd[1]: Started MADEBYJPBD Refresh xmobar script.
Feb 10 18:23:29 T420 refreshxmobar[3984]: present
Feb 10 18:23:42 T420 systemd[1]: Started MADEBYJPBD Refresh xmobar script.

I still can't put my finger on what i am doing wrong hmm

thanks.


ThinkPad P16s AMD / KDE

Offline

#5 2016-02-11 02:17:03

Docbroke
Member
From: India
Registered: 2015-06-13
Posts: 1,475

Re: custom service not starting

did you reboot after enabling the service?
you have removed service type, I suggest 'Type=simple'

also try running your script directly in terminal, what does it do,

refreshxmobar

if the script works as intended, next step is to look at your service, if scipt doesn't work fix it first. I am not using xmobar so can not test it.

Offline

#6 2016-02-11 09:45:39

Raynman
Member
Registered: 2011-10-22
Posts: 1,539

Re: custom service not starting

Docbroke wrote:

did you reboot after enabling the service?
you have removed service type, I suggest 'Type=simple'

What would a reboot accomplish? It's tied to sleep, not boot. And "simple" is implied, but then xmobar shouldn't be backgrounded -- with the script as it is, setting it to "forking" would prevent xmobar from being killed when the script exits.

But that would probably only make it work for the first time you resume from sleep, because the service will already be running when subsequent sleeps are initiated. As a quick fix, you could try it as follows. Start xmobar (from ~/.xinitrc or similar) with a small wrapper script like this:

while :; do xmobar; done

And combine this with a oneshot service that runs after sleep.target and simply kills xmobar (so you can do without the refreshxmobar script and the Environment setting).

Offline

#7 2016-02-11 13:33:38

Docbroke
Member
From: India
Registered: 2015-06-13
Posts: 1,475

Re: custom service not starting

After enabling service it starts on next boot.
When I first created service for slock to start after sleep, it did immediately lock the screen on starting the service but didn't lock after suspend, but when I did enable it it was working as intended. Some services works well only after reboot, simply starting the service didn't work well.

Offline

Board footer

Powered by FluxBB