0
Answered

Start at boot on Ubuntu? Deamonize?

Jim Howe 6 years ago updated by Tom 4 years ago 24
I love what I am seeing here.  I can run it with no problems from the command line with scripts provided.  I have tried following linux documentation to get it to run headless at boot time (copied to the /etc/init.d, owned by root, etc), but I am having no luck.  Any thoughts or links that may help?

Thanks in advance!
Under review
I am not using Ubuntu myself, so I did not test anything, but you should be able to run Ubooquity as a daemon by following this tutorial:

http://zerocool.is-a-geek.net/running-java-program-as-a-daemon-in-ubuntu-linux/
Hi Tom!

I will give it a shot and report with what I find.

Thanks again!
Jim
Hi Tom,

I've been playing around with the scripts and have found that even when declaring the fully qualified path to the install directory containing the Ubooqity.jar file, it appears to ignore it and creates the logs, cache, theme directories and the rest of the files in the path from which the script is being called.

This becomes a problem in having a script call the Ubooquity.jar command from the /etc/init.d directory where the startup scripts are located.  It recreates a new instance of the Ubooquity files within the /etc/init.d directory which will cause problems shutting down and starting up the system (not to mention propagating the application into a path where it does not belong).

I'm not sure if it is by design that the jar file will populate its required files structure to the path from which the script is run (it does make for a quick and easy install) or if there is some other parameter to pass along to it within the script to point to an absolute path where the expected files are to (and may already) reside.

Thanks for your help!
Jim
Hi, ok, reporting back with success.

Looking further into the comments section of the link you provided, it appears adding a line at the beginning to change to my program directory solved the issue with propagating the files into the /etc/init.d:

 cd /opt/ubooquity

Apparently the author's java file contained a line:
System.setProperty("user.dir", args[0]); 
to enable the setting of the working directory upon its launch.

Looking good so far!  Thanks for the help!
You solved your problem faster than I was able to answer. :)
The solution is indeed to go into the directory you want to use before calling the "java" command.

If you really want to be ablre to specify your "working directory" (although I can"t think of a scenario where you could not simply go into the directory to launch Ubooquity), you can do it by explicitely setting the Java "user.dir" property:

java -Duser.dir="/my/directory" - jar /path/to/the/jar/file/Ubooquity.jar

But I don't really recommend that solution as it could have unintended side effects (I don't know any but it's safer to just use your method).

I'm glad it's working now. Don't hesitate to let me know if you have other questions.

Another reliable solution is daemontools.  It essentially daemonizes the jar while also restarting the service if it happens to die, and it comes with flexible logging options.

http://isotope11.com/blog/manage-your-services-wit...

Here are the two scripts I use to set up my service:

#!/bin/sh
#/etc/service/ubooquity/run

cd /opt/ubooquity/
exec 2>&1
exec java -jar /opt/ubooquity/Ubooquity.jar -webadmin -headless
#!/bin/sh
#/etc/service/ubooquity/log/run

exec multilog s10485760 n5 /var/log/ubooquity
The ubooquity/run script is set up to always run from /opt/ubooquity to keep the database in one place and also combines STDERR with STDOUT for logging.  The ubooquity/log/run script rotates the log after 10MB and retains 5 previous.
Thanks, Charlie!  This looks like what I need.  Gonna try it soon.
I've read over these tutorials and I'm still pretty confused. 

I've put ubooquity in /opt/Ubooquity and I'm able to run it from the command line, i just don't understand how to make it run at start up. 
Ubuntu Server 14.04.2 LTS

Also i found a script that said put this in ubooquity.conf in /etc/init and run it, but it gave me a bunch of errors. 

  start on runlevel [3]
  stop on shutdown

  expect fork

  script
  cd /opt/Ubooquity

  java -jar Ubooquity.jar -webadmin -port 9093 -headless
  emit ubooquity_running
  end script
+2
Hi Zackery, 

I am on Ubuntu Server 14.10.  Here are my notes if they may be any help to you (or anyone else for that matter).  It may not be the most elegant solution, but it is solid enough for me.

Cheers,
Jim
This worked great! Thanks

Hi Jim,


I just found your script to deamon-ise ubooquity, it works like a charm, with one caveat.


Im wanting to add the extra mem, but when i uncomment the line #MEM_OPTS. the service refuses to start giving an error:


'Command line arguments error: joptsimple.UnrecognizedOptionException: X is not a recognized option'


Any ideas?


Thanks again for providing the script.


Porph!


Update, i had a look at a couple of other scripts and the $MEM_OPTS was placed just after java and before the -jar...if that makes sense, so all sorted


cheers for the script!!

Update, i had a look at a couple of other scripts and the $MEM_OPTS was placed just after java and before the -jar...if that makes sense, so all sorted

That's because the memory option is intended for the Java Virtual Machine, not the Ubooquity program itself (which is running inside the JVM).

@jim

thanks man, that seems to have done the trick!
Hey!  Glad to hear it! 
Hi Jim,

Thanks a lot for sharing your notes!!
I lost the HDD of my debian and had to all re-install from scratch.
Your script prevented me to rewrite it.
I just had to change the directory and it worked like a charm :-)

@Tom: it should be aded to the help page (except if I missed it, it is not)

Cheers,
Mat
The script is available on the download page.
I'll add an entry in the FAQ.

By the way, there was a typo in my script (which is also in Jim's script):
#$MEM_OPT=-Xmx512m
should be
#MEM_OPT=-Xmx512m
(remove the $)
Hey Matt! Glad they helped! Getting into jams like that is the reason I started keeping notes like these myself for Linux stuff especially.
The easiest way would be to set a cron job. This is how I did it on my server.



Mind you, this is is via ssh from my laptop. You can probably ignore the -headless option if you don't need it. I use it because my server is headless.

hello guys, I am super new to linux, just playing around with it, and I manage to set Ubooquity and all, but I did noticed that when I restart my server machine, it doest boot up, I need to open manualy Ubooquity.jar any help? thanks! (Do I use the scrip thats in the download page?)

Hello,

The script on the download page is just a manual start/stop script for command line usage, it won't start Ubooquity automatically with your system.

Do do that you'll need to either run it as a daemon, or use a cron job.


Both solution are described in this thread above. :)

Here's the upstart script I use on Ubuntu:


#Ubooquity startup script


setuid (user)
setgid (group)

start on runlevel [2345]
stop on runlevel [016]

expect fork

script
cd /path/to/ubooquity
java -jar Ubooquity.jar -webadmin -port 2202 -headless
end script