Systemd Bitlbee service script

Hi.

I’m trying to get my systemd bitlbee script to start, I can successfully run it manually but it doesn’t startup on boot.
The process does run on boot, but it does not load the correct config file I want to run it with:

[Unit]
Description=bitlbee irc/im gateway
After=network.target

[Service]
User=bitlbee
Group=bitlbee
Type=forking
ExecStart=/usr/local/sbin/bitlbee -F -c /etc/bitlbee/bitlbee.conf
Restart=on-failure

[Install]
WantedBy=multi-user.target

On boot, systemctl status bitlbee returns loaded (inactive).
When I run it manually, it returns active (running).

This also conflicts with the process started on boot, I have to manually kill this process as sudo.

How can I debug my script?
Thanks.

Hi Georgie,

When you run it manually are you doing so as user OSMC?

Does the user & group bitlbee exist?

you could try

[Unit]
Description=bitlbee irc/im gateway
After=network.target

[Service]
User=osmc
Group=osmc
Type=forking
ExecStart=/usr/local/sbin/bitlbee -F -c /etc/bitlbee/bitlbee.conf
Restart=on-failure

[Install]
WantedBy=multi-user.target

Thanks Tom.

Hi, thanks for your reply.

I created both the user and group - bitlbee and when I run it manually it does run as the bitlbee user.
I don’t wanna use the osmc user/group for security reasons.

Is there any way I can debug my script?
Systemd seems to provide little info when the service is dead.

sudo journalctl should give more information

Hi Georgie,

I’ve also just checked the bitlbee.conf at the master:

## User:
## 
## If BitlBee is started by root as a daemon, it can drop root privileges,
## and change to the specified user.
##
# User = bitlbee

So from looking at this I would try un-commenting user in the conf file and start the systemd service as osmc, and see if it runs on start?

Or drop user & group from the systemd service file.

Thanks Tom.

Hi Tom,

I have already uncommented that line.
I changed the service to start as osmc and it still runs under bitlbee which is what I want.
But, the service does not load the /etc/bitlbee/bitlbee.conf configuration file that I’m running as an option.

It currently loads with the /usr/local/sbin/bitlbee -I option, which does not include the file above.
Without it, my settings aren’t loaded and I can’t even kill that PID process unless I kill it under sudo -s.

Here’s my journalctl output: https://pastebin.com/pSGpvFnC

Hi,

This may not be the issue:

Apr 24 22:36:09 osmc2 systemd[1]: Configuration file /etc/systemd/system/bitlbee.service is marked executable. Please remove executable permission bits. Proceeding anyway.

issue: sudo chmod 0644 /usr/lib/systemd/system/bitlbee.service

and reboot.

Hi,

Also try the systemd unit file, without user & group so:

[Unit]
Description=bitlbee irc/im gateway
After=network.target

[Service]
Type=forking
ExecStart=/usr/local/sbin/bitlbee -F -c /etc/bitlbee/bitlbee.conf
Restart=on-failure

[Install]
WantedBy=multi-user.target

Thanks Tom.

Hi Tom,

sudo chmod 0644 /usr/lib/systemd/system/bitlbee.service returns:
chmod: cannot access '/usr/lib/systemd/system/bitlbee.service': No such file or directory

Also, running the systemd unit file without the user & group still does not load the service:

  • bitlbee.service - bitlbee irc/im gateway
    Loaded: loaded (/etc/systemd/system/bitlbee.service; enabled)
    Active: inactive (dead)

It’s as if root is running bitlbee before the systemd service gets to execute.

Hi,

Apologies that should have been:

sudo chmod 0644 /etc/systemd/system/bitlbee.service

And reboot, if that fails I’ve found systemd unit from fedora, which may work. I’ve may modifications to suit:

[Unit]
Description=bitlbee irc/im gateway
After=network.target

[Service]
Type=forking
ExecStartPre=/usr/bin/mkdir -p /run/bitlbee
ExecStartPre=/usr/bin/chown bitlbee.bitlbee /run/bitlbee
ExecStart=/usr/sbin/bitlbee -F -u bitlbee -c /etc/bitlbee/bitlbee.conf
PIDFile=/run/bitlbee/bitlbee.pid
ExecReload=/bin/kill -HUP $MAINPID
KillMode=process
Restart=always

[Install]
WantedBy=multi-user.target

sudo systemctl daemon-reload

and restart

Thanks Tom.

Hi Guys.

The usual location for the bitlbee.service file should be in /lib/systemd/system. Service files are configuration data and are therefore not executable.

When you enable / disable the service using systemctl what happens is that systemd will make / remove a symbolic link somewhere under /etc/systemd/system. Since the [Install] section says WantedBy=multi-user.target, the symbolic link will be created in /etc/systemd/system/multi-user.target.wants.

As Tom_Doyle rightly says, if you change anything in the bitlbee.service file, you need to run sudo systemctl daemon-reload for it to be picked up by systemd.

1 Like

Hi Georgie,

I’ve had a play with this out of curiosity, and it seems the maintainer for package is providing an init.d script, which is compatible with the systemd sysv init compatibility mode.

I would try this:

sudo systemctl disable bitlbee.service #This should remove the symlink /etc/systemd/system/bitlbee.service

sudo rm /lib/systemd/system/bitlbee.service #not required for sysv init compatibility mode.

sudo systemctl daemon-reload

sudo systemctl enable bitlbee #If you do not receive a prompt confirming the service has been enabled, then please reinstall bitlbee & bitlbee-common

sudo systemctl start bitlbee.

Confirm bitlbee has started as expected, if so restart osmc and confirm if starting as required.

@dillthedog good spot on /lib/systemd/system, copy paste error.

Thanks Tom.

I figured you originally meant sudo chmod 0644 /etc/systemd/system/bitlbee.service, it still didn’t work though.

I also added your suggestions above according to the unit from fedora and still get the same results.
But, this time I get the following error:

  • bitlbee.service - bitlbee irc/im gateway
    Loaded: loaded (/etc/systemd/system/bitlbee.service; enabled)
    Active: failed (Result: start-limit) since Tue 2017-04-25 18:24:19 CST; 9s ago
    Process: 975 ExecStartPre=/usr/bin/mkdir -p /run/bitlbee (code=exited, status=203/EXEC)

Apr 25 18:24:19 osmc2 systemd[1]: Failed to start bitlbee irc/im gateway.
Apr 25 18:24:19 osmc2 systemd[1]: Unit bitlbee.service entered failed state.
Apr 25 18:24:19 osmc2 systemd[1]: bitlbee.service holdoff time over, scheduling restart.
Apr 25 18:24:19 osmc2 systemd[1]: Stopping bitlbee irc/im gateway…
Apr 25 18:24:19 osmc2 systemd[1]: Starting bitlbee irc/im gateway…
Apr 25 18:24:19 osmc2 systemd[1]: bitlbee.service start request repeated too quickly, refusing to start.
Apr 25 18:24:19 osmc2 systemd[1]: Failed to start bitlbee irc/im gateway.
Apr 25 18:24:19 osmc2 systemd[1]: Unit bitlbee.service entered failed state.

EDIT: Noticed that mkdir binary should be under /bin/mdkir
EDIT2: Also corrected /run/bitlbee.pid

I compiled my own bitlbee package since I’m using some particular add-ons that need the latest available version.

I was actually using the init.d script from the maintainer package, but after I updated/upgraded my bitlbee package it broke.

Hi Tom,

After modifying the systemd fedora unit you provided, the service still runs as /usr/local/sbin/bitlbee -I. If I run it manually, it works well but I still have to kill the PID created on boot to run the fork with the configuration file that I need.

Hi Georgie,

Apologies I’d forgotten about the folder structure difference between fedora & debian, could you please post the modified bitlbee.service.

Also Can you please confirm you are saving the bitlbee.service to /lib/systemd/system and running sudo systemctl daemon-reload, as dillthedog pointed out yesterday.

Also I seen a link yesterday that you can compile bitlbee with systemd support, which I assume creates the correct systemd unit file. I can’t find the link at the moment, please standby.

Thanks Tom.

Hi Georgie,

I would considered trying to recompile again, by adding --systemdsystemunitdir=/lib/systemd/system to configure flag, so e.g.

./configure --etcdir=/etc/bitlbee --systemdsystemunitdir=/lib/systemd/system

Thanks Tom.

Hi Tom,

Oops, I had not seen the @dillthedog’s comment. Thanks.
I modified the /lib/systemd/system/bitlbee.service file to this:

[Unit]
Description=BitlBee IRC/IM gateway
After=network.target

[Service]
ExecStartPre=/bin/mkdir -p /run/bitlbee
ExecStartPre=/bin/chown bitlbee.bitlbee /run/bitlbee
ExecStart=/usr/local/sbin/bitlbee -F -u bitlbee -c /etc/bitlbee/bitlbee.conf
PIDFile=/run/bitlbee.pid
ExecReload=/bin/kill -HUP $MAINPID
KillMode=process
Restart=on-failure

[Install]
WantedBy=multi-user.target 

When I run the script manually, it never finishes loading. Systemctl status returns:

  • bitlbee.service - bitlbee irc/im gateway
    Loaded: loaded (/etc/systemd/system/bitlbee.service; enabled)
    Active: activating (start) since Tue 2017-04-25 19:11:28 CST; 7s ago
    Control: 898 (bitlbee)
    CGroup: /system.slice/bitlbee.service
    `-898 /usr/local/sbin/bitlbee -F -n

Apr 25 19:11:28 osmc2 systemd[1]: Starting bitlbee irc/im gateway…

I do run systemctl daemon-reload every time I make changes to the unit.
On boot, the same root bitlbee process always runs as: /usr/local/sbin/bitlbee -I

I see you removed Type=forking. It will default to Type=simple, which might not be appropriate.

I still think this should be:

As /run isn’t owned by user bitlbee, where as /run/bitlbee/ is (due to “ExecStartPre=/bin/chown bitlbee.bitlbee /run/bitlbee”).

drop -u bitlbee, as the user is already being set in the conf file (Sorry I forgot yesterday, that you had already set this), so:

ExecStart=/usr/local/sbin/bitlbee -F -c /etc/bitlbee/bitlbee.conf

Sorry I’ve not used this app, what does -I & -F Flags do?

When you compiled, did you enabled systemd support? If not you may need to do this before the systemd scripts work as expected.

Thanks Tom.