2

I want to run weechat constantly in the background so that I can ssh in and reattach to it via screen.

I'm trying to accomplish this via the following file in /etc/init/chatscreen.conf:

description     "Run a persistent weechat within a screen"

start on runlevel [2345]

respawn

setuid chat
setgid chat

exec /usr/bin/screen -S chatscreen -Dm /usr/bin/weechat

Then I run sudo initctl start chatscreen to start the service, which prints chatscreen start/running, process 3090.

When I run sudo initctl status chatscreen a moment later, it prints chatscreen stop/waiting, and no screen or weechat processes are running according to htop.

dmesg shows the following errors:

[ 5649.430032] init: chatscreen main process ended, respawning
[ 5649.454638] init: chatscreen main process ended, respawning
[ 5649.476572] init: chatscreen main process ended, respawning
...
[ 5649.608818] init: chatscreen main process ended, respawning
[ 5649.627409] init: chatscreen respawning too fast, stopped

No /var/log/upstart/chatscreen.log file exists.

When I ssh in as the chat user and run /usr/bin/screen -S chatscreen -Dm /usr/bin/weechat in the shell, it executes as expected. (It runs the command and blocks. I can then start another ssh session, screen -r, /exit weechat, and the original screen command returns.)

I'm running Ubuntu Server 14.04.1 LTS 64-bit on DigitalOcean.

EDIT: I also tried using dtach instead of screen. The only difference is that I had to use expect fork because dtach -n forks. dtach -n can be run without a terminal, which I thought might be a problem with screen.

Unfortunately, I went through the same respawning cycle without any corresponding log file in /var/log/upstart. But dmesg did say: init: chatdtach main process (1073) terminated with status 1 multiple times.

0

Upstart, even when using setuid, does not set the HOME environment variable. weechat tries to use this variable to look up its configuration directory when -d is not specified.

weechat prints Error: unable to get HOME directory in response to this problem. However, it went unlogged because weechat had nowhere to output this error except for stdout, which screen/dtach did nothing with except dutifully return because the original process ended.

You can check if this is your problem by changing the exec line to this:

exec /usr/bin/weechat

If /var/log/upstart/chatscreen.log says Error: unable to get HOME directory, then this was the problem.

Here is a corrected upstart service file:

description     "Run a persistent weechat within screen"

respawn

setuid chat
setgid chat

# Not sure if screen needs this.
env LANG=en_US.utf8

exec screen -S chatscreen weechat -d /home/chat/.weechat

Or if you prefer the light-weight dtach:

description     "Run a persistent weechat within dtach"

respawn

setuid chat
setgid chat

expect fork

env LANG=en_US.utf8

exec dtach -n /home/chat/chatdtach.sock weechat -d /home/chat/.weechat

The LANG environment variable is so that weechat recognizes the detacher as supporting UTF-8. Without this, my weechat was displaying strange boxes on the right side instead of the vertical nick list separator. Change it to whatever locale you'd like to use.

I'm not sure if screen requires LANG. I only tested it with dtach.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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