Results 1 to 10 of 10

Thread: Daemonize certain processes -> Stuck with script

  1. #1

    Default Daemonize certain processes -> Stuck with script

    All,

    This weekend I was working on setting up my XBMC server. To do this is need to run serveral programs, but I came to the conclusion that init is changed to systemd.
    Not a problem you should say, however with init you could create daemon processes, which I could not find with systemd.
    Solution was to build my own Daemonizer script per program where needed (since the programs I wanted to don't have PID).

    So after searching I found the folowing script:
    How to Daemonize in Linux [Doug Potter]

    Problem is that I don't see how to use it. Of course I did fill in the daemon name and run as user.

    After that I can compile with:
    gcc -Wall daemon_script.c -o deamon

    Which can be executed, but there doesn't happen a thing, so probably I do something wrong.
    Please help me out, read complete artikel on the website but doesn't give me a clue?

    Update:
    Oke, working a little however a PID in /var/run is still missing and I get an error on:
    "/var/lock/subsys/"

    Because that folder does not exist on OpenSuSe 12.1. Hoe should this be adjusted to make it working.
    Furthermore, how do I get a PID.

  2. #2
    Join Date
    Feb 2009
    Location
    Spain
    Posts
    25,547

    Default Re: Daemonize certain processes -> Stuck with script

    On 2012-06-03 13:56, TUDStudent wrote:
    >
    > All,
    >
    > This weekend I was working on setting up my XBMC server. To do this is
    > need to run serveral programs, but I came to the conclusion that init is
    > changed to systemd.
    > Not a problem you should say, however with init you could create daemon
    > processes, which I could not find with systemd.


    I'm sure you can launch with systemd any program as was done with systemv -
    but don't ask me how.

    Being a daemon or not is a secondary thing.

    --
    Cheers / Saludos,

    Carlos E. R.
    (from 11.4 x86_64 "Celadon" at Telcontar)

  3. #3
    Join Date
    Jun 2008
    Location
    Germany
    Posts
    301

    Default Re: Daemonize certain processes -> Stuck with script

    Hello, writing systemd unit files is pretty simple, it's more straight forward than for the good old init. I will demonstrate it on a short example:
    Code:
      [Unit]  Description=My cool daemon  After=mysql.service    [Service]  User=daemon_user  ExecStart=/usr/local/bin/daemon    [Install] WantedBy=multi-user.target
    If your daemon depends on some other processes you should add it to After section. Maybe you also want to replace daemon_user with the your spcific daemon user. Then copy this file to /etc/systemd/system/daemon.service, reload configuration with
    Code:
     systemctl --system daemon-reload
    and start it with systemctl start daemon.service that's it. To enable it on startup just type systemctl enable daemon.service. It's really quite simple, isn't it Hope this helps

  4. #4
    Join Date
    Jun 2008
    Location
    Netherlands
    Posts
    25,271

    Default Re: Daemonize certain processes -> Stuck with script

    I am afraid that @Monex, while using CODE tags, did not realy copied/pasted directly from the terminal into the post. Thus the Line feeds are gone. Can you please repost or this this realy as it should be?
    Henk van Velden

  5. #5
    Join Date
    Jun 2008
    Location
    Germany
    Posts
    301

    Default Re: Daemonize certain processes -> Stuck with script

    Hello,

    in preview it looked quite good

    Here the version with corrected code tags

    writing systemd unit files is pretty simple, it's more straight forward than for the good old init. I will demonstrate it on a short example:
    Code:
     
    [Unit] 
    Description=My cool daemon 
    After=mysql.service  
    
    [Service] 
    User=daemon_user 
    ExecStart=/usr/local/bin/daemon  
    
    [Install] WantedBy=multi-user.target
    If your daemon depends on some other processes you should add it to After section. Maybe you also want to replace daemon_user with the your spcific daemon user.

    Then copy this file to /etc/systemd/system/daemon.service, reload configuration with

    Code:
     systemctl --system daemon-reload
    and start it with systemctl start daemon.service that's it.

    To enable it on startup just type systemctl enable daemon.service. It's really quite simple, isn't it

    Hope this helps

  6. #6
    Join Date
    Jun 2008
    Location
    Netherlands
    Posts
    25,271

    Default Re: Daemonize certain processes -> Stuck with script

    Thanks for the repost.

    It realy is simple and it is shown here earlier. But I allways forget where to find it.
    Will now make a copy of your example in a file here. Hope I will remember I have that file somewhere when tiimes comes
    Henk van Velden

  7. #7

    Default Re: Daemonize certain processes -> Stuck with script

    Jun 3 22:00:18 linux-7ffb systemd[1608]: Failed at step EXEC spawning /usr/local/bin/daemon: No such file or directory
    Jun 3 22:00:18 linux-7ffb systemd[1]: daemon.service: main process exited, code=exited, status=203
    Jun 3 22:00:18 linux-7ffb systemd[1]: Unit daemon.service entered failed state.

    Getting the above error in my messages. Do I mis an RPM to get this working, or is it located somewhere else.
    (I really do not have this folder/file -> Opensuse 12.1)

  8. #8
    Join Date
    Jun 2008
    Location
    Netherlands
    Posts
    25,271

    Default Re: Daemonize certain processes -> Stuck with script

    Don't you understand that you have to fill in your parameters? E.g. for the example of /usr/local/bin/deamon you should of course replace it wiith the path to your own script, wherever it may be. And of course all the others. I would not believe you also use a name as "My cool deamon"?????
    Henk van Velden

  9. #9

    Default Re: Daemonize certain processes -> Stuck with script

    Ha such an idea, but then I understand why you gave me this solution (i already have an .service file which forks).

    However the program I run, in this case "newcs", which is a cardsharing server is not 100% deamon and does not store its pid in /var/run

    Therefore I am having problems with running it as forking service.
    Do you have a solution to this?

    This is the reason I wanted to build my own daemon script.

  10. #10
    Join Date
    Jun 2008
    Location
    Groningen, Netherlands
    Posts
    19,987
    Blog Entries
    14

    Default Re: Daemonize certain processes -> Stuck with script

    To be honest, I cannot match the various statements you're posting. But it does raise a question: have you been trying to do this on WIndows?

    To be a service or a daemon, is not determined by whether there's a pid file in /var/run. Take a look at the existing .service files, at some of the scripts in /etc/init.d

    Consider a "while true do " construction, run it in the background by adding " &" to the script/command.
    ° Appreciate my reply? Click the star and let me know why.

    ° Perfection is not gonna happen. No way.

    https://en.opensuse.org/openSUSE:Board#Members
    http://en.opensuse.org/User:Knurpht
    http://nl.opensuse.org/Gebruiker:Knurpht

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •