brndnmtthws / conky

Light-weight system monitor for X, Wayland (sort of), and other things, too
https://conky.cc
GNU General Public License v3.0
7.28k stars 620 forks source link

systemd service file failed to start #673

Closed GopherJ closed 6 years ago

GopherJ commented 6 years ago
[Unit]
Description=Conky System Monitor
After=network.target
StartLimitIntervalSec=0

[Service]
Type=simple
ExecStart=/usr/bin/conky
Restart=always
User=root
RestartSec=1

[Install]
WantedBy=multi-user.target
Alias=conky.service

Hello, I want to start conky as a service in ubuntu 18.10, I wrote a service config file like this but it failed to start.

dbriba commented 6 years ago

What do you want to do with this service ?

GopherJ commented 6 years ago

I just want it to execute as a daemon so that I can manage it width systemctl

dbriba commented 6 years ago

Have you see that : https://linux.die.net/man/1/daemonize But I do not know if this is appropriate for conky. To use conky you must run this program with the command "conky -c /path/of/your/conky/file "

GopherJ commented 6 years ago

Hello, I've successfully executed the conky program without arguments so I wrote /usr/bin/conky directly.

In my case conky -c /path/of/your/conky/config/file -d works well, but I want to manage it with systemd and enable it to start automatically when I restart my machine.

GopherJ commented 6 years ago

I've tried crontab it also fails...Any one could help me to solve the problem ?

# crontab -e and I've added this
@reboot /usr/bin/conky -c '/home/$(whoami)/.conkyrc" -d > /dev/null 2>&1 &
dbriba commented 6 years ago

To start conky automatically I use a script bash wich is launch by my kde's session : `#!/bin/bash

/home/dominique/.conkyrc/conky-1.10/conky-meteo/conky-aubagne-2/weather.sh sleep 5 conky -c /home/dominique/.conkyrc/conky-1.10/conky_monitor/conky-monitor & sleep 5 conky -c /home/dominique/.conkyrc/conky-1.10/conky-meteo/conky-aubagne-2/conky-meteo2 & sleep 5 conky -c /home/dominique/.conkyrc/conky-1.10/conky-saint/conky-saint & sleep 3 conky -c /home/dominique/.conkyrc/conky-1.10/conky-calendrier/conky-calendrier & sleep 3 conky -c /home/dominique/.conkyrc/conky-1.10/conky-soleil/conky-soleil & `

plikhari commented 6 years ago

@GopherJ As has been pointed out - it is a good idea to use a sh script to run rather than use /usr/bin/conky straight up.

You need to create a background conky process with & at the end OR use -d in the line in question.

It is not the same the way you run a script in the terminal - it is being run with you as the user while the instance in the service will be a root instance - which you state in the [Service] section. In this case you must have all your files in the root location and not in the user home folder location.

A thought does come in the mind - why do you want conky to run as root ??

GopherJ commented 6 years ago

@plikhari Thanks for your reply! I don't want conky to run as root. I just want to be able to manage it by systemd. As you can see that I didn't specify the config file, so it will use the default config of conky. It shouldn't be related with root.

GopherJ commented 6 years ago

Here is my config :

script

# /usr/local/bin/conky-start
/usr/bin/conky -c "/home/cheng/.conkyrc" -d > /dev/null 2>&1 &

service

# /lib/systemd/system/conky.service
[Unit]
Description=Conky System Monitor
StartLimitIntervalSec=0

[Service]
Type=simple
# ExecStart=/usr/local/bin/conky-start
ExecStart=conky-start
Restart=always
User=cheng
Group=cheng
RestartSec=1

[Install]
WantedBy=multi-user.target
Alias=conky.service

And when I try to start the service using :

systemctl daemon-reload
systemctl start conky

it fails.

plikhari commented 6 years ago

Hi Good morning - perhaps it was too late in the night for me re my last message.

What you are trying to achieve is not doable since systemd only handles system events. conky is working on the command line or after a Desktop Environment has started. Try finding out what happened to the service at start sudo systemctl status conky.service - you will probably see that it is inactive and dead. There is no GUI for conky to show and it exits at the start with systemd.

Every Desktop Environment that is there has an ability to start a program during the DE start time - you should use that.

cheers

Please close this issue as this issue stands resolved.

lasers commented 6 years ago

I don't want conky to run as root.

mkdir -p ~/.config/systemd/user
[Unit]
Description=Conky - A system monitor for X.
[Service]
ExecStart=conky -c %h/.config/conky/config
[Install]
WantedBy=graphical.target
systemctl --user enable conky
systemctl --user start conky
systemctl --user stop conky

You can keep your config in ~/.config/conky/config. Don't change background = false.

The tricky part is to figure out how to start conky properly after Login, Xorg, etc... but...

I just want to be able to manage it by systemd.

Cool. I hope this is good enough. You just have to remember --user and no sudo.

GopherJ commented 6 years ago

@lasers Thanks for your help! Now the status of the conky service is active, but it seems there is still a problem.

In /usr/lib/systemd/user I added the service file conky.service, this file is owned by $(whoami), its group is also $(whoami) :

[Unit]
Description=Conky System Monitor
StartLimitIntervalSec=0

[Service]
Type=simple
ExecStart=conky -c %h/.conkyrc
Restart=always
User=cheng
Group=cheng
RestartSec=1

[Install]
WantedBy=graphical.target
Alias=conky.service

my config file is /home/$(whoami)/.conkyrc :

-- vim: ts=4 sw=4 noet ai cindent syntax=lua

conky.config = {
    alignment = 'top_right',
    background = false,
    border_width = 0.5,
    cpu_avg_samples = 4,
    default_color = 'white',
    default_outline_color = 'grey',
    default_shade_color = 'black',
    draw_borders = true,
    draw_graph_borders = true,
    draw_outline = false,
    draw_shades = false,
    use_xft = true,
    font = 'DejaVu Sans Mono:size=10',
    gap_x = 5,
    gap_y = 50,
    minimum_height = 5,
    minimum_width = 5,
    net_avg_samples = 2,
    double_buffer = true,
    out_to_console = false,
    out_to_stderr = false,
    extra_newline = false,
    own_window = true,
    own_window_colour = '000000',
    own_window_class = 'Conky',
    own_window_argb_visual = true,
    own_window_argb_count = 0,
    own_window_type = 'dock',
    own_window_transparent = true,
    own_window_hints = 'undecorated,below,sticky,skip_taskbar,skip_pager',
    stippled_borders = 0,
    update_interval = 1,
    uppercase = false,
    use_spacer = 'none',
    show_graph_scale = false,
    show_graph_range = false
}

conky.text = [[
${image ~/.face -p 180,5 -s 70x70 -f 86400}${image ~/.pacman -p 20,9 -s 60x60 -f 86400}
${font Latin Modern Mono Caps:bold:size=14}${alignc}${color 00ffae}$nodename
${font Noto Sans:bold:size=8}${alignc}${desktop_name} ${desktop}/$desktop_number
${font Noto Sans:bold:size=8}${alignc}    ${exec hostnamectl | grep System | cut -c21-40}
${alignc}   ${exec hostnamectl | grep Architecture | cut -c7-30}
${alignc}   ${exec hostnamectl | grep Kernel | cut -c13-32}
${font Entopia:bold:size=12}${color 33E9FF}PERFORMANCE ${hr 2}${font}
${offset 15}${color FFFDE2}System Uptime ${alignr}$color $uptime
${offset 15}${color FFFDE2}RAM :$color $mem $memperc% ${color yellow}${membar 4}
${offset 15}${color FFFDE2}Swap:$color $swap/$swapmax $swapperc% ${color yellow}${swapbar 4}
${offset 15}${color FFFDE2}Battery: ${battery_percent BAT1}% ${color yellow}${alignr}${battery_bar 4, 130 BAT1}
${offset 25}${font DejaVu Sans Mono:size=8}${battery_time BAT1}${font DejaVu Sans Mono:size=8}${color FFFDE2}
${offset 15}Core 1   ${color ff8300}${cpubar cpu1 6}${color FFFDE2}
${offset 15}Core 2   ${color ff8300}${cpubar cpu2 6}${color FFFDE2}
${offset 15}Core 3   ${color ff8300}${cpubar cpu3 6}${color FFFDE2}
${offset 15}Core 4   ${color ff8300}${cpubar cpu4 6}${color FFFDE2}
${offset 15}${font}${color FFFDE2}Procs:$color $processes  ${color FFFDE2}Run:$color $running_processes Temp: ${acpitemp}°C

${font Entopia:bold:size=12}${color green}NETWORK ${hr 2}${font DejaVu Sans Mono:size=9}
${offset 15}${color}Ext IP Addr ${color red}${alignr}${exec curl ipinfo.io/ip}
${offset 15}${color}IPv4 Addr ${color red}${alignr}${addr enp8s0}
${offset 15}${color green}${font}▼ $color${totaldown enp8s0} ${alignr}${color green}▲ $color${totalup enp8s0}
${offset 5}${font Entopia:bold:size=12}${color orange}${wireless_essid wlp10s0f0} ${stippled_hr 1}
${offset 15}${color}${font DejaVu Sans Mono:size=9}WiFi ${alignr}${wireless_link_qual_perc 
wlp10s0f0}%(${wireless_link_qual wlp10s0f0}/${wireless_link_qual_max wlp10s0f0}) ${color red}${addr wlp10s0f0}
${offset 15}${font}${color green}▼ $color${totaldown wlp10s0f0} ${alignr}${color green}▲ $color${totalup wlp10s0f0}

${font Entopia:bold:size=12}${color red}PROCESSES ${hr 2}
${offset 15}${font Noto sans:size=8}${color EDE0FF}Name               ${alignr}PID   CPU%   MEM%
${offset 15}${color FF7878}${top name 1} ${alignr}${top pid 1} ${top cpu 1} ${top mem 1}
${offset 15}${color FF7878}${top name 2} ${alignr}${top pid 2} ${top cpu 2} ${top mem 2}
${offset 15}${color FF7878}${top name 3} ${alignr}${top pid 3} ${top cpu 3} ${top mem 3}
${offset 15}${color FF7878}${top name 4} ${alignr}${top pid 4} ${top cpu 4} ${top mem 4}
${font Entopia:bold:size=12}${color 00ffae}FORTUNE ${hr 2}$color
${offset 15}${font Noto Sans:size=10}${execi 600 fortune -s | fold -s -w44}
]]

then I created the symbolic link by using :

systemctl enable conky --user

and then started by :

systemctl start conky --user

I've got no output in terminal and here is the status of the service :

$ systemctl status conky --user

● conky.service - Conky System Monitor
   Loaded: loaded (/usr/lib/systemd/user/conky.service; enabled; vendor preset: enabled)
   Active: active (running) since Tue 2018-10-30 10:39:40 CET; 1ms ago
 Main PID: 8097 ((conky))
   CGroup: /user.slice/user-1000.slice/user@1000.service/conky.service
           └─8097 (conky)

Oct 30 10:39:40 jiang systemd[2161]: Started Conky System Monitor.
Oct 30 10:39:40 jiang systemd[8097]: conky.service: Failed to determine supplementary groups: Operation not permitted
Oct 30 10:39:40 jiang systemd[8097]: conky.service: Failed at step GROUP spawning /usr/bin/conky: Operation not permitted
Oct 30 10:39:40 jiang systemd[2161]: conky.service: Main process exited, code=exited, status=216/GROUP
Oct 30 10:39:40 jiang systemd[2161]: conky.service: Failed with result 'exit-code'.

the status turns to activating after a few seconds:

● conky.service - Conky System Monitor
   Loaded: loaded (/usr/lib/systemd/user/conky.service; enabled; vendor preset: enabled)
   Active: activating (auto-restart) (Result: exit-code) since Tue 2018-10-30 10:41:46 CET; 563ms ago
  Process: 8246 ExecStart=/usr/bin/conky -c /home/cheng/.conkyrc (code=exited, status=216/GROUP)
 Main PID: 8246 (code=exited, status=216/GROUP)

Here is the output of journalctl -u conky --user :

-- Logs begin at Tue 2018-08-14 00:16:39 CEST. --
Oct 30 10:42:57 jiang systemd[2161]: conky.service: Main process exited, code=exited, status=216/GROUP
Oct 30 10:42:57 jiang systemd[2161]: conky.service: Failed with result 'exit-code'.
Oct 30 10:42:59 jiang systemd[2161]: conky.service: Service RestartSec=1s expired, scheduling restart.
Oct 30 10:42:59 jiang systemd[2161]: conky.service: Scheduled restart job, restart counter is at 814.
Oct 30 10:42:59 jiang systemd[2161]: Stopped Conky System Monitor.
Oct 30 10:42:59 jiang systemd[2161]: Started Conky System Monitor.
Oct 30 10:42:59 jiang systemd[8364]: conky.service: Failed to determine supplementary groups: Operation not permitted
Oct 30 10:42:59 jiang systemd[8364]: conky.service: Failed at step GROUP spawning /usr/bin/conky: Operation not permitted
Oct 30 10:42:59 jiang systemd[2161]: conky.service: Main process exited, code=exited, status=216/GROUP
Oct 30 10:42:59 jiang systemd[2161]: conky.service: Failed with result 'exit-code'.
Oct 30 10:43:00 jiang systemd[2161]: conky.service: Service RestartSec=1s expired, scheduling restart.
Oct 30 10:43:00 jiang systemd[2161]: conky.service: Scheduled restart job, restart counter is at 815.
Oct 30 10:43:00 jiang systemd[2161]: Stopped Conky System Monitor.
Oct 30 10:43:00 jiang systemd[2161]: Started Conky System Monitor.
Oct 30 10:43:00 jiang systemd[8366]: conky.service: Failed to determine supplementary groups: Operation not permitted
Oct 30 10:43:00 jiang systemd[8366]: conky.service: Failed at step GROUP spawning /usr/bin/conky: Operation not permitted
Oct 30 10:43:00 jiang systemd[2161]: conky.service: Main process exited, code=exited, status=216/GROUP
Oct 30 10:43:00 jiang systemd[2161]: conky.service: Failed with result 'exit-code'.
Oct 30 10:43:01 jiang systemd[2161]: conky.service: Service RestartSec=1s expired, scheduling restart.
Oct 30 10:43:01 jiang systemd[2161]: conky.service: Scheduled restart job, restart counter is at 816.
Oct 30 10:43:01 jiang systemd[2161]: Stopped Conky System Monitor.
Oct 30 10:43:01 jiang systemd[2161]: Started Conky System Monitor.
Oct 30 10:43:01 jiang systemd[8367]: conky.service: Failed to determine supplementary groups: Operation not permitted
Oct 30 10:43:01 jiang systemd[8367]: conky.service: Failed at step GROUP spawning /usr/bin/conky: Operation not permitted
Oct 30 10:43:01 jiang systemd[2161]: conky.service: Main process exited, code=exited, status=216/GROUP
Oct 30 10:43:01 jiang systemd[2161]: conky.service: Failed with result 'exit-code'.
Oct 30 10:43:02 jiang systemd[2161]: conky.service: Service RestartSec=1s expired, scheduling restart.
Oct 30 10:43:02 jiang systemd[2161]: conky.service: Scheduled restart job, restart counter is at 817.
Oct 30 10:43:02 jiang systemd[2161]: Stopped Conky System Monitor.
Oct 30 10:43:02 jiang systemd[2161]: Started Conky System Monitor.
Oct 30 10:43:02 jiang systemd[8368]: conky.service: Failed to determine supplementary groups: Operation not permitted
Oct 30 10:43:02 jiang systemd[8368]: conky.service: Failed at step GROUP spawning /usr/bin/conky: Operation not permitted
Oct 30 10:43:02 jiang systemd[2161]: conky.service: Main process exited, code=exited, status=216/GROUP
Oct 30 10:43:02 jiang systemd[2161]: conky.service: Failed with result 'exit-code'.
qOct 30 10:43:04 jiang systemd[2161]: conky.service: Service RestartSec=1s expired, scheduling restart.
Oct 30 10:43:04 jiang systemd[2161]: conky.service: Scheduled restart job, restart counter is at 818.
Oct 30 10:43:04 jiang systemd[2161]: Stopped Conky System Monitor.
Oct 30 10:43:04 jiang systemd[2161]: Started Conky System Monitor.
Oct 30 10:43:04 jiang systemd[8369]: conky.service: Failed to determine supplementary groups: Operation not permitted
Oct 30 10:43:04 jiang systemd[8369]: conky.service: Failed at step GROUP spawning /usr/bin/conky: Operation not permitted
Oct 30 10:43:04 jiang systemd[2161]: conky.service: Main process exited, code=exited, status=216/GROUP
Oct 30 10:43:04 jiang systemd[2161]: conky.service: Failed with result 'exit-code'.
aOct 30 10:43:05 jiang systemd[2161]: conky.service: Service RestartSec=1s expired, scheduling restart.
Oct 30 10:43:05 jiang systemd[2161]: conky.service: Scheduled restart job, restart counter is at 819.
Oct 30 10:43:05 jiang systemd[2161]: Stopped Conky System Monitor.
Oct 30 10:43:05 jiang systemd[2161]: Started Conky System Monitor.
Oct 30 10:43:05 jiang systemd[8370]: conky.service: Failed to determine supplementary groups: Operation not permitted
Oct 30 10:43:05 jiang systemd[8370]: conky.service: Failed at step GROUP spawning /usr/bin/conky: Operation not permitted
Oct 30 10:43:05 jiang systemd[2161]: conky.service: Main process exited, code=exited, status=216/GROUP
Oct 30 10:43:05 jiang systemd[2161]: conky.service: Failed with result 'exit-code'.
qOct 30 10:43:06 jiang systemd[2161]: conky.service: Service RestartSec=1s expired, scheduling restart.
Oct 30 10:43:06 jiang systemd[2161]: conky.service: Scheduled restart job, restart counter is at 820.
Oct 30 10:43:06 jiang systemd[2161]: Stopped Conky System Monitor.
Oct 30 10:43:06 jiang systemd[2161]: Started Conky System Monitor.
Oct 30 10:43:06 jiang systemd[8372]: conky.service: Failed to determine supplementary groups: Operation not permitted
Oct 30 10:43:06 jiang systemd[8372]: conky.service: Failed at step GROUP spawning /usr/bin/conky: Operation not permitted
Oct 30 10:43:06 jiang systemd[2161]: conky.service: Main process exited, code=exited, status=216/GROUP
Oct 30 10:43:06 jiang systemd[2161]: conky.service: Failed with result 'exit-code'.

Any help will be appreciated! Thanks!

GopherJ commented 6 years ago

I think it will be cool if conky could support systemd out of box !

lasers commented 6 years ago

I had issue with Alias=conky.service. Removed that and your config works okay for me. I'm on Arch though. Permissions (ie Operation not permitted) seems to be an issue here.

Oct 30 10:43:00 jiang systemd[8366]: conky.service: Failed to determine supplementary groups: Operation not permitted
Oct 30 10:43:00 jiang systemd[8366]: conky.service: Failed at step GROUP spawning /usr/bin/conky: Operation not permitted

Remove this from the config, enable, etc.

User=cheng
Group=cheng

... and try again. Otherwise, I dunno. Maybe ask systemctl, linux channels on IRC for some help.

GopherJ commented 6 years ago

It seems can be started after removing User, Group, but there is still some problems and I don't see why.

Closed and hope conky can support systemd out of box.

lasers commented 6 years ago

but there is still some problems and I don't see why.

What problems exactly? To be honest, it may be more of systemd issue than conky issue. You're sure to receive better support from systemd, linux channels than conky channel.

conky can support systemd out of box.

Sure. It is definitely something to look into.

My interpretation of this issue is that if conky can be a server and having clients connecting to this server, then it would be worth making it possible out of box (currently not possible right now).

If conky is X11 application out of the box (which it is), then it might not be a good idea to do this... We could add systemd unit/service (user and global) to conky/wiki right after we figure out how to make this work flawlessly for user and global. This is just my interpretation though.

LinuxOnTheDesktop commented 5 years ago

A reason to run conky as a systemd service - a user systemd service - is as follows. Using such a service with a dependence upon graphical.target might solve the problem that on Cinnamon conky fails to display if not run some hard-to-determine-and-variable-in-multiple-ways number of seconds after logon.