LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   problem starting daemon remotely (https://www.linuxquestions.org/questions/linux-newbie-8/problem-starting-daemon-remotely-879215/)

alenD 05-06-2011 11:03 AM

problem starting daemon remotely
 
Hello,
i have remote access to Linux machine (ubuntu) and i need to start my program there as a daemon.
I created a script at /etc/init.d , i can start it but its behavior is strange - it does not write into the logs, all output goes to console.

Here is the main part of the script that i use to start the program:

start-stop-daemon --start --pidfile $PIDFILE --exec $DAEMON -- $DAEMON_ARGS --background

What am i doing wrong?

thank you

r3sistance 05-07-2011 06:18 AM

not sure, the details are little hard to go by here, if you want everything logged you could redirect all output to a log file via adding "> /mypath/mylog.log 2>1&" to the end of the command line (naturally changing /mypath/mylog.log to the actual path/logfile) however does the daemon continue to run when the terminal/console session is closed? if so you may want to use nohup as a prefix...

if you don't care about the output you could just a fix a & at the this should make it a background task.

This is about the best answer I can give from what I can see (and given I am not overly familiar with Ubuntu). If this doesn't help maybe a bit more information about the daemon you are trying to run?

alenD 05-07-2011 04:42 PM

Thanks for responding.
Right now i want to run a simple test program (below), attempting to write to logfile...
Using nohup helps - the process (the java program) continues to run when leaving the parent shell, still cannot see that the program is working ('ps' shows that the process is running but no output).
Thanks again for help.


import java.io.*;
import java.util.*;

public class TestN{

public static void main(String[] args){
try{
File file = new File("mytest");
BufferedWriter out = new BufferedWriter(new FileWriter(file));
int i = 5;
for(;;){
// try{
System.out.println("test!!");
out.append("test" + i+ "\n");
i++;
out.flush();
try{
Thread.sleep(2000);
}
catch(InterruptedException e){
}
// }
// System.out.println("Error!");
// }
}
// out.close();
}
catch(IOException e){
}
}
}

r3sistance 05-08-2011 01:12 AM

Hi,

as I said use "> /mypath/mylog.log 2>1&" at the end of the line, where mypath/mylog.log is replaced with the actual log file (I.E. /var/log/myservice.log). This should then put ALL output in said log file.

Alternatively download screen and run the process in screen.

You can just start a screen terminal with say

screen -S mysession [command]

from there start your daemon, then hit ^a then d to drop a screen terminal but everything in it will continue to run and then you can reattach to the screen session with

screen -r mysession

note if you start screen with a command, that screen session will terminate when that command is finished (I.E. if started with the daemon, stopping the daemon would terminate the screen session).


All times are GMT -5. The time now is 12:06 PM.