Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

I'm using Debian Jessie with the latest updates. I made a systemd service to run a script when my server starts. Here's its configuration:

[Unit]
Description=(my description)

[Service]
ExecStart=/usr/bin/bot
Restart=restart-always

[Install]
WantedBy=multi-user.target

/usr/bin/bot is a script running a Mono executable. It consists of:

#!/bin/bash
(cd /path/to/my/executable && mono bot.exe)

(I replaced the path here, but the one on my script is correct.)

When I run the script /usr/bin/bot normally (simply /usr/bin/bot on my terminal), it is working as expected. top reports it's using between 0 and, say, 20% of my CPU, which is normal. But when I start it with service bot start, top says it's always using at least 100% of my CPU.

In both cases bot is working as expected.

What could explain such a big difference in CPU usage?

Thank you.

share|improve this question
    
Have you tried this on any other systemd based systems? Jessie isn't a stable release yet. Might be good to bring this to their attention. –  Devon Mar 21 at 14:32
    
I'll install Wheezy and try. –  Pierre-Loup Pagniez Mar 21 at 14:35
    
Wheezy only included a tech preview of systemd. So I don't know if it will be any different. systemd is new to the Debian and Ubuntu scene. Here is a list of distributions: en.wikipedia.org/wiki/Systemd#Adoption_and_reception –  Devon Mar 21 at 14:37
    
Oh, right. Well, I don't actually need to use systemd, I only started using it because after upgrading to Jessie (I believe), my inittab wasn't taken into account anymore, probably because it was using systemd instead. Though there are other scripts that Debian runs with systemd, and those don't use 100% CPU. But I'd rather not go back to SysV since systemd is probably going to be widespread in the future. –  Pierre-Loup Pagniez Mar 21 at 14:42
3  
It doesn't really make sense for this to be a systemd bug if it is literally the bot process which is using all the CPU. Systemd is not magical and can't affect your program's behavior beyond starting it, sending it signals, and perhaps killing it. –  goldilocks Mar 21 at 15:12

1 Answer 1

I "fixed it" by putting my bot under a screen, like so:

[Unit]
Description=(my description)

[Service]
RemainAfterExit=yes
ExecStart=/usr/bin/screen -dmS bot /usr/bin/bot
Restart=restart-always

[Install]
WantedBy=multi-user.target

I don't know why putting my process in a screen fixes its high CPU usage, but hey, it works.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.