How do make a program run at startup

Questions about using 3rd party Media Streaming software may go here
Forum rules
We've moved! Head over to Synology Community (community.synology.com) to meet up with our team and other Synology enthusiasts!
johnh123
Beginner
Beginner
Posts: 25
Joined: Mon Apr 02, 2012 9:21 pm

How do make a program run at startup

Unread post by johnh123 » Wed Apr 25, 2012 12:29 am

I'm wanting to use streambaby for video streaming. I can start it from the command line and it works ok, but if I close the cli, then it goes away. Following is the code that is in the file to get it going - is there somewhere I can put this so it will always start up?

#!/bin/bash
cd /usr/homes/streambaby
DIRNAME=`dirname $0`
java -Djava.net.preferIPv4Stack=true -Xmx256m -jar "$DIRNAME/jbin/streambaby.jar" $@

User avatar
maxxfi
Compiler
Compiler
Posts: 6794
Joined: Sun Dec 27, 2009 12:13 pm
Location: Espoo, Finland

Re: How do make a program run at startup

Unread post by maxxfi » Wed Apr 25, 2012 6:19 am

Add it at the end of /etc/rc.local (before the 'exit 0' :) ) and if necessary 'daemonize it' (let it run in background)
No longer using Synology NAS, moved to more open source solutions.
DS-106j > DS-210j > DS-411

johnh123
Beginner
Beginner
Posts: 25
Joined: Mon Apr 02, 2012 9:21 pm

Re: How do make a program run at startup

Unread post by johnh123 » Wed Apr 25, 2012 10:51 pm

Thanks, how do I 'daemonize it'?

User avatar
maxxfi
Compiler
Compiler
Posts: 6794
Joined: Sun Dec 27, 2009 12:13 pm
Location: Espoo, Finland

Re: How do make a program run at startup

Unread post by maxxfi » Thu Apr 26, 2012 6:24 am

At a bare minimum you launch the script with a & at the end (so that it starts in background).
You can take some idea by looking at how services are launched in /usr/syno/etc/rc.d/
No longer using Synology NAS, moved to more open source solutions.
DS-106j > DS-210j > DS-411

User avatar
DaveHamilton
Apprentice
Apprentice
Posts: 89
Joined: Fri Aug 17, 2012 10:47 pm

Re: How do make a program run at startup

Unread post by DaveHamilton » Fri Aug 17, 2012 10:50 pm

I've found that putting 'nohup' in front of java commands helps to daemonize them and keep them running even after the user logs out.

In your example:

nohup java -Djava.net.preferIPv4Stack=true -Xmx256m -jar "$DIRNAME/jbin/streambaby.jar" $@

Hex23
I'm New!
I'm New!
Posts: 5
Joined: Sun Jan 20, 2013 6:27 am

Re: How do make a program run at startup

Unread post by Hex23 » Sun Jan 20, 2013 6:37 am

Anyone have a specific solution to this they can confirm works? I'm trying to get streambaby to run on my new DS713+ and can't find any solution that seems to work.

I'm having the common problem where my init scripts will run just fine if I manually run them from a shell, but after trying lots of different init script configurations, I can't get it to start properly on reboot.

I read another thread that clued me in to the idea that the Java environment variables may not be set yet. So I set them within the script. No go.

Also tried both directly running it vs. using the supplied java service wrapper. Neither work.

Hex23
I'm New!
I'm New!
Posts: 5
Joined: Sun Jan 20, 2013 6:27 am

Re: How do make a program run at startup

Unread post by Hex23 » Sun Jan 20, 2013 11:12 pm

OK, after further debugging I found the all the following init environment problems.

1) JAVA_HOME and CLASSPATH need to be set
2) Java is not in the PATH yet
Apparently these first two happen via /etc/.profile
3) It looks like streambaby has a bug where if launched with cwd = "/" it throws an exception. The problem is in StreamBabyConfig::getCurDir()

Once I workaround these I can get it to work fine.

johnh123
Beginner
Beginner
Posts: 25
Joined: Mon Apr 02, 2012 9:21 pm

Re: How do make a program run at startup

Unread post by johnh123 » Mon Mar 24, 2014 5:56 am

What are the workarounds needed?

Locked

Return to “Media Streaming Mods”