LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-06-2011, 12:03 PM   #1
alenD
Member
 
Registered: Jul 2005
Posts: 69

Rep: Reputation: 15
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
 
Old 05-07-2011, 07:18 AM   #2
r3sistance
Senior Member
 
Registered: Mar 2004
Location: UK
Distribution: CentOS 6/7
Posts: 1,179

Rep: Reputation: 107Reputation: 107
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?

Last edited by r3sistance; 05-07-2011 at 07:29 AM.
 
Old 05-07-2011, 05:42 PM   #3
alenD
Member
 
Registered: Jul 2005
Posts: 69

Original Poster
Rep: Reputation: 15
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){
}
}
}
 
Old 05-08-2011, 02:12 AM   #4
r3sistance
Senior Member
 
Registered: Mar 2004
Location: UK
Distribution: CentOS 6/7
Posts: 1,179

Rep: Reputation: 107Reputation: 107
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).

Last edited by r3sistance; 05-08-2011 at 02:15 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Starting KDE remotely kgalan Fedora 2 12-08-2005 04:11 PM
Starting KDE remotely kgalan Linux - Newbie 1 12-06-2005 07:18 AM
Starting X remotely Intacto Linux - Newbie 4 11-28-2005 11:36 PM
Add users remotely, daemon? The Jesus Linux - Networking 1 08-14-2003 11:56 AM
Starting system log daemon problem trub Linux From Scratch 1 02-19-2002 01:11 PM


All times are GMT -5. The time now is 05:39 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration