I am trying to create an Upstart job that starts a new screen session on boot, in which I would like to automatically start a java executable. Here is the .conf file I am currently trying to get to work, although I have tried several others:

description     "Run the bungeecord jar"

start on (local-filesystems and net-device-up IFACE=eth0 and runlevel [2345])
stop on runlevel [016]

exec start-stop-daemon --start -c ridog --exec /usr/bin/screen -- -dmUS BungeeCord java -server -XX:UseSSE=4 -XX:+UseCMSCompactAtFullCollection -XX:MaxPermSize=356m -XX:ParallelGCThreads=6 -XX:+UseConcMarkSweepGC -XX:+DisableExplicitGC -XX:+CMSIncrementalMode -XX:+CMSIncrementalPacing -XX:+UseCompressedOops -XX:+AggressiveOpts -Xmx256M -jar BungeeCord.jar

pre-stop script
    screen -S BungeeCord -X foo "end^M"
end script

To my knowledge, the script seems to work fine, I can run sudo start bungeecord and get the intended result, however, restarting the machine does not work. Instead, I get this error in the /var/log/upstart/bungeecord.log:

Cannot make directory '/var/run/screen': Permission denied

I've looked up this error and the search results are obscure and inconclusive. I've tried running the command as root, this removes the error but still no screen session. I've tried different commands like this:

su ridog -c "screen -dmS BungeeCord java -jar /home/ridog/BungeeCord/BungeeCord.jar"
  • How are you sure that the screen session isn't started as root? Please start a program in screen that way that cannot fail (like sleep 1000). Jun 23, 2014 at 22:44
  • No luck using the command screen -dmS test sleep 1000. No screen sockets running in both the root account and my own upon reboot. However, no errors in the log. Jun 23, 2014 at 23:13
  • If I execute screen -dmS test sleep 1000 via crontab then there is the expected screen session. Trying with cron may be easier for you anyway. Jun 24, 2014 at 1:30

3 Answers 3


Invoking screen via upstart is indeed somewhat tricky. The first problem regarding non-existing /var/run/screen can be easily solved though.

On Ubuntu 10.10 to 13.10 there is an upstart task which is responsible for cleaning up and (re-)creating /var/run/screen on bootup so you need to make sure your upstart script will run after it:

start on stopped screen-cleanup

On Ubuntu 10.04 and earlier as well as Ubuntu 14.04 and later that code is in the init script /etc/init.d/screen-cleanup which means upstart jobs can refer to it as the result of rc:

start on stopped rc

However, screen will probably still complain about /var/run/screen permissions. This can be workarounded by invoking screen via setsid:

exec setsid screen -Dm /some/command

Your screen session will fork once, so you need to add the "expect fork" stanza to make sure upstart follows the correct pid.

Here's a complete example script (needs at least Ubuntu 12.04):

# screen startup script
# requires upstart v1.4 or newer

description "running top in screen session"

start on ( local-filesystems
           and stopped rc )
stop on runlevel [!2345]


setuid test
setgid test

# "setsid screen -Dm" only forks once
expect fork

# use setsid to avoid screen complaining about /var/run/screen permissions.
exec setsid screen -Dm -S mytopsession /usr/bin/top
  • Doesn't the last line of the example script start an useless instance of top ? Is it necessary to launch it even if the program itself won't be used ? Mar 12, 2016 at 22:26
  • 1
    You need to replace top with whatever application you want to run inside your screen session of course. I only used top for the example because it's well-known and available on most systems. Mar 15, 2016 at 7:22

Create /var/run/screen as root with the appropriate permissions before you make the screen call.


Problem solved, I switched from using upstart to using cron. It was much more simple and everything works great now.

For anyone reading this that might be curious as to how I did it, I made a simple shell script:

java -Xms256M -Xmx256M -jar /home/ridog/BungeeCord/BungeeCord.jar

And set it to run on startup with a new line in crontab -e:

@reboot screen -dmS BungeeCord sh /home/ridog/BungeeCord/run.sh

Thanks for your help!


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .