Skip to content

correct systemd integration #87

Closed
Closed

Description

@Geal

In gitlab by @Geal on Nov 15, 2016, 11:07

right now, we have a simple systemd service file, for a single process writing logs to stdout. In the near future, the proxy will use a main process with a few worker processes.

Questions:

  • how to make a service file work correctly with a multiprocess arch?
  • how to handle logging from the workers?

apparently, there's a KillMode=mixedoption to kill all the process in the cgroup. Ideally, in the case of a restart, the parent process would receive the signal and restart the workers itself, since it knows how to give them the relevant data.
Right now, the workers will log on stdout, but they could send messages to syslog instead.

@Keruspe @divarvel what do you think?

Activity

  1. Geal commented on Jan 18, 2017

    @Geal
    MemberAuthor

    In gitlab by @Keruspe on Nov 15, 2016, 14:06

    The systemd service actually "watches" only the main process.

    While the main process runs, the service is running,.

    When the main process exits 0, the service is noted as success and all the children are killed (unless asked to "RemainAfterExit").

    When the main process exits != 0, the service is marked as failed and all the children are killed.

    By default, children inherit stdout/stderr from the maain process so everything logged to stdout or stderr go through the main process FDs and are grabbed by systemd. Otherwise syslog is probably the simplest solution.

    For the KillMode thing, we use mixed atm for haproxy. man systemd.kill has some info on the options regarding killing processes. Here is the part about KillMode

           KillMode=
               Specifies how processes of this unit shall be killed. One of control-group, process, mixed, none.
    
               If set to control-group, all remaining processes in the control group of this unit will be killed on unit stop (for services: after the stop command is executed, as configured with ExecStop=). If set to process, only the main process itself is killed. If set to mixed, the SIGTERM signal (see below) is sent to the main process while the subsequent SIGKILL signal (see below) is sent to all remaining processes of the
               unit's control group. If set to none, no process is killed. In this case, only the stop command will be executed on unit stop, but no process be killed otherwise. Processes remaining alive after stop are left in their control group and the control group continues to exist after stop unless it is empty.
    
               Processes will first be terminated via SIGTERM (unless the signal to send is changed via KillSignal=). Optionally, this is immediately followed by a SIGHUP (if enabled with SendSIGHUP=). If then, after a delay (configured via the TimeoutStopSec= option), processes still remain, the termination request is repeated with the SIGKILL signal (unless this is disabled via the SendSIGKILL= option). See kill(2) for more
               information.
    
               Defaults to control-group.
    
  2. Geal commented on Jan 18, 2017

    @Geal
    MemberAuthor

    In gitlab by @Keruspe on Nov 15, 2016, 14:10

    Regarding the scope feature, you can see it as a "folder" for cgroups.

    Scopes units manage a set of system processes. Unlike service units, scope units manage externally created processes, and do not fork off processes on its own.

    Long story short:

    • either we have one service, which forks its children and so on
    • or we have sevral services launching independent binaries and we can put those into a same scope to regroup all the different components.
  3. Geal commented on Jan 18, 2017

    @Geal
    MemberAuthor

    In gitlab by @Keruspe on Nov 15, 2016, 14:12

    Example of scope: the most common usage is for user sessions, to regroup all the software launched by the user in her session.

  4. Geal commented on Jan 18, 2017

    @Geal
    MemberAuthor

    In gitlab by @Geal on Nov 15, 2016, 14:29

    what happens when multiple children write to stdout at the same time?

  5. Geal commented on Jan 18, 2017

    @Geal
    MemberAuthor

    In gitlab by @Keruspe on Nov 15, 2016, 14:33

    The same thing that happens with multithreading, the logs are in the correct order for each process, but with logs from others processes in the middle.

  6. Geal commented on Aug 17, 2017

    @Geal
    MemberAuthor

    ok so right now I have this:

    [Unit]                            
    Description=Rust HTTP reverse proxy                                  
    
    [Service]                         
    Environment=RUST_LOG=info         
    Environment=RUST_BACKTRACE=1      
    WorkingDirectory=/root/conf-sozu                                
    ExecStart=/root/sozu/target/release/sozu start -c config.toml      
    
    [Install]                         
    WantedBy=multi-user.target 
    

    Where should I go from there?
    cc @Keruspe

  7. added this to the needed for the release milestone on Aug 17, 2017
  8. Keruspe commented on Aug 21, 2017

    @Keruspe
    Member

    Can you list exactly the things that you want, the behaviour you expect?

  9. Geal commented on Aug 21, 2017

    @Geal
    MemberAuthor

    I just want to be sure it would work correctly with sozu and its worker processes (IIRC there was an issue with systemd wanting to manage the workers itself, right?) and the binary upgrades

  10. Keruspe commented on Aug 21, 2017

    @Keruspe
    Member

    You can give KillMode=mixed a look, apart from that, I don't see any specific recommendation for "basic" usage

  11. Keruspe commented on Aug 22, 2017

    @Keruspe
    Member

    Do we want/need some kind of "Reload"? I think that would be the correct way to handle sozu upgrades. Do sozu answer to a unix signal for that?
    How do we want to handle the "restart"? Should the master process and all of its children be killed?

  12. Geal commented on Aug 22, 2017

    @Geal
    MemberAuthor

    sozu upgrades are managed by a config message, because it requires a small dance between the master and its workers. I'm not sure that's something systemd can manage correctly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions