Skip to content

Commit

Permalink
[hostcfgd] Configure service auto-restart in hostcfgd. (sonic-net#5744)
Browse files Browse the repository at this point in the history
Before this change, a process running inside every SONiC container dealt with FEATURE table 'auto_restart' field and depending on the value decided whether a container has to be killed or not.
If killed service auto restart mechanism restarts the container.
This change moves the logic from container to the host daemon - hostcfgd.
The 'auto_restart' handling is kept in supervisor-proc-exit-listener but now it is not required for container that wants to support auto restart feature.

hostcfgd refactoring - move feature handling in another class.
override systemd service Restart= setting from hostcfgd.
remove default systemd Restart=always.
Signed-off-by: Stepan Blyshchak stepanb@nvidia.com

- Why I did it

Remove the need to deal with container orchestration logic from the container itself. Leave this logic to the orchestrator - host OS.

- How I did it

hostcfgd configures 'Restart=' value for systemd service.

- How to verify it

root@r-tigon-11:/home/admin# sudo config feature autorestart lldp enabled
root@r-tigon-11:/home/admin# show feature status | grep lldp
lldp            enabled   enabled
root@r-tigon-11:/home/admin# docker exec -it lldp pkill -9 lldpd
root@r-tigon-11:/home/admin# docker ps -a | grep lldp
65058396277c        docker-lldp:latest                   "/usr/bin/docker-lld…"   2 days ago          Exited (0) 20 seconds ago                       lldp
root@r-tigon-11:/home/admin# docker ps -a | grep lldp
65058396277c        docker-lldp:latest                   "/usr/bin/docker-lld…"   2 days ago          Up 5 seconds                            lldp
root@r-tigon-11:/home/admin# sudo config feature autorestart lldp disabled
root@r-tigon-11:/home/admin# docker exec -it lldp pkill -9 lldpd
root@r-tigon-11:/home/admin# docker ps -a | grep lldp
65058396277c        docker-lldp:latest                   "/usr/bin/docker-lld…"   2 days ago          Up 35 seconds                           lldp
root@r-tigon-11:/home/admin# docker ps -a | grep lldp
65058396277c        docker-lldp:latest                   "/usr/bin/docker-lld…"   2 days ago          Exited (0) 3 seconds ago                       lldp
root@r-tigon-11:/home/admin# docker ps -a | grep lldp
65058396277c        docker-lldp:latest                   "/usr/bin/docker-lld…"   2 days ago          Exited (0) 39 seconds ago                       lldp
root@r-tigon-11:/home/admin#
  • Loading branch information
stepanblyschak authored and Carl Keene committed Aug 7, 2021
1 parent b1623e7 commit b8a50b3
Show file tree
Hide file tree
Showing 19 changed files with 295 additions and 171 deletions.
1 change: 0 additions & 1 deletion files/build_templates/dhcp_relay.service.j2
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ User={{ sonicadmin_user }}
ExecStartPre=/usr/bin/{{ docker_container_name }}.sh start
ExecStart=/usr/bin/{{ docker_container_name }}.sh wait
ExecStop=/usr/bin/{{ docker_container_name }}.sh stop
Restart=always
RestartSec=30

[Install]
Expand Down
1 change: 0 additions & 1 deletion files/build_templates/nat.service.j2
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ User={{ sonicadmin_user }}
ExecStartPre=/usr/bin/{{docker_container_name}}.sh start
ExecStart=/usr/bin/{{docker_container_name}}.sh wait
ExecStop=/usr/bin/{{docker_container_name}}.sh stop
Restart=always
RestartSec=30

[Install]
Expand Down
1 change: 0 additions & 1 deletion files/build_templates/per_namespace/bgp.service.j2
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ ExecStartPre=/usr/local/bin/{{docker_container_name}}.sh start{% if multi_instan
ExecStart=/usr/local/bin/{{docker_container_name}}.sh wait{% if multi_instance == 'true' %} %i{% endif %}
ExecStop=/usr/local/bin/{{docker_container_name}}.sh stop{% if multi_instance == 'true' %} %i{% endif %}

Restart=always
RestartSec=30

[Install]
Expand Down
1 change: 0 additions & 1 deletion files/build_templates/per_namespace/database.service.j2
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ User=root
ExecStartPre=/usr/bin/{{docker_container_name}}.sh start{% if multi_instance == 'true' %} %i{% endif %}
ExecStart=/usr/bin/{{docker_container_name}}.sh wait{% if multi_instance == 'true' %} %i{% endif %}
ExecStop=/usr/bin/{{docker_container_name}}.sh stop{% if multi_instance == 'true' %} %i{% endif %}
Restart=always
RestartSec=30

[Install]
Expand Down
1 change: 0 additions & 1 deletion files/build_templates/per_namespace/lldp.service.j2
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ User={{ sonicadmin_user }}
ExecStartPre=/usr/bin/{{docker_container_name}}.sh start{% if multi_instance == 'true' %} %i{% endif %}
ExecStart=/usr/bin/{{docker_container_name}}.sh wait{% if multi_instance == 'true' %} %i{% endif %}
ExecStop=/usr/bin/{{docker_container_name}}.sh stop{% if multi_instance == 'true' %} %i{% endif %}
Restart=always
RestartSec=30

[Install]
Expand Down
1 change: 0 additions & 1 deletion files/build_templates/per_namespace/swss.service.j2
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ Environment=sonic_asic_platform={{ sonic_asic_platform }}
ExecStartPre=/usr/local/bin/swss.sh start{% if multi_instance == 'true' %} %i{% endif %}
ExecStart=/usr/local/bin/swss.sh wait{% if multi_instance == 'true' %} %i{% endif %}
ExecStop=/usr/local/bin/swss.sh stop{% if multi_instance == 'true' %} %i{% endif %}
Restart=always
RestartSec=30

[Install]
Expand Down
1 change: 0 additions & 1 deletion files/build_templates/per_namespace/teamd.service.j2
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ User={{ sonicadmin_user }}
ExecStartPre=/usr/local/bin/{{docker_container_name}}.sh start{% if multi_instance == 'true' %} %i{% endif %}
ExecStart=/usr/local/bin/{{docker_container_name}}.sh wait{% if multi_instance == 'true' %} %i{% endif %}
ExecStop=/usr/local/bin/{{docker_container_name}}.sh stop{% if multi_instance == 'true' %} %i{% endif %}
Restart=always
RestartSec=30

[Install]
Expand Down
1 change: 0 additions & 1 deletion files/build_templates/pmon.service.j2
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ User={{ sonicadmin_user }}
ExecStartPre=/usr/bin/{{docker_container_name}}.sh start
ExecStart=/usr/bin/{{docker_container_name}}.sh wait
ExecStop=/usr/bin/{{docker_container_name}}.sh stop
Restart=always
RestartSec=30

[Install]
Expand Down
1 change: 0 additions & 1 deletion files/build_templates/radv.service.j2
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ User={{ sonicadmin_user }}
ExecStartPre=/usr/local/bin/{{ docker_container_name }}.sh start
ExecStart=/usr/local/bin/{{ docker_container_name }}.sh wait
ExecStop=/usr/local/bin/{{ docker_container_name }}.sh stop
Restart=always
RestartSec=30

[Install]
Expand Down
1 change: 0 additions & 1 deletion files/build_templates/restapi.service.j2
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ User={{ sonicadmin_user }}
ExecStartPre=/usr/bin/{{docker_container_name}}.sh start
ExecStart=/usr/bin/{{docker_container_name}}.sh wait
ExecStop=/usr/bin/{{docker_container_name}}.sh stop
Restart=always
RestartSec=30

[Install]
Expand Down
1 change: 0 additions & 1 deletion files/build_templates/sflow.service.j2
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ User={{ sonicadmin_user }}
ExecStartPre=/usr/bin/{{docker_container_name}}.sh start
ExecStart=/usr/bin/{{docker_container_name}}.sh wait
ExecStop=/usr/bin/{{docker_container_name}}.sh stop
Restart=always
RestartSec=30

[Install]
Expand Down
1 change: 0 additions & 1 deletion files/build_templates/share_image/database.service.j2
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ User=root
ExecStartPre=/usr/bin/{{docker_container_name}}.sh start chassisdb
ExecStart=/usr/bin/{{docker_container_name}}.sh wait chassisdb
ExecStop=/usr/bin/{{docker_container_name}}.sh stop chassisdb
Restart=always
RestartSec=30

[Install]
Expand Down
1 change: 0 additions & 1 deletion files/build_templates/snmp.service.j2
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,4 @@ StartLimitBurst=3
ExecStartPre=/usr/bin/{{docker_container_name}}.sh start
ExecStart=/usr/bin/{{docker_container_name}}.sh wait
ExecStop=/usr/bin/{{docker_container_name}}.sh stop
Restart=always
RestartSec=30
1 change: 0 additions & 1 deletion files/build_templates/telemetry.service.j2
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,4 @@ User={{ sonicadmin_user }}
ExecStartPre=/usr/bin/{{docker_container_name}}.sh start
ExecStart=/usr/bin/{{docker_container_name}}.sh wait
ExecStop=/usr/bin/{{docker_container_name}}.sh stop
Restart=always
RestartSec=30
Loading

0 comments on commit b8a50b3

Please sign in to comment.