Restart teleport.service and background process been killed

Hi guys
if i put process into background and systemctl restart teleport restart teleport. whether nohup or not that process always been killed
i’m writte a script for test

#!/bin/bash
echo “hello”
#catch all possible signal
trap 'echo recived SIGHUP , now exiting…; ’ SIGHUP
trap 'echo recived SIGABRT , now exiting…; ’ SIGABRT
trap 'echo recived SIGSEGV , now exiting…; ’ SIGSEGV
trap 'echo recived SIGSTKFLT , now exiting…; ’ SIGSTKFLT
trap 'echo recived SIGTTIN , now exiting…; ’ SIGTTIN
trap 'echo recived SIGVTALRM , now exiting…; ’ SIGVTALRM
trap 'echo recived SIGSYS , now exiting…; ’ SIGSYS
trap 'echo recived SIGRTMIN+4 , now exiting…; ’ SIGRTMIN+4
trap 'echo recived SIGRTMIN+9 , now exiting…; ’ SIGRTMIN+9
trap 'echo recived SIGRTMIN+14 , now exiting…; ’ SIGRTMIN+14
trap 'echo recived SIGRTMAX-11 , now exiting…; ’ SIGRTMAX-11
trap 'echo recived SIGRTMAX-6 , now exiting…; ’ SIGRTMAX-6
trap 'echo recived SIGRTMAX-1 , now exiting…; ’ SIGRTMAX-1
trap 'echo recived SIGINT , now exiting…; ’ SIGINT
trap 'echo recived SIGBUS , now exiting…; ’ SIGBUS
trap 'echo recived SIGUSR2 , now exiting…; ’ SIGUSR2
trap 'echo recived SIGCHLD , now exiting…; ’ SIGCHLD
trap 'echo recived SIGTTOU , now exiting…; ’ SIGTTOU
trap 'echo recived SIGPROF , now exiting…; ’ SIGPROF
trap 'echo recived SIGRTMIN , now exiting…; ’ SIGRTMIN
trap 'echo recived SIGRTMIN+5 , now exiting…; ’ SIGRTMIN+5
trap 'echo recived SIGRTMIN+10 , now exiting…; ’ SIGRTMIN+10
trap 'echo recived SIGRTMIN+15 , now exiting…; ’ SIGRTMIN+15
trap 'echo recived SIGRTMAX-10 , now exiting…; ’ SIGRTMAX-10
trap 'echo recived SIGRTMAX-5 , now exiting…; ’ SIGRTMAX-5
trap 'echo recived SIGRTMAX , now exiting…; ’ SIGRTMAX
trap 'echo recived SIGQUIT , now exiting…; ’ SIGQUIT
trap 'echo recived SIGFPE , now exiting…; ’ SIGFPE
trap 'echo recived SIGPIPE , now exiting…; ’ SIGPIPE
trap 'echo recived SIGCONT , now exiting…; ’ SIGCONT
trap 'echo recived SIGURG , now exiting…; ’ SIGURG
trap 'echo recived SIGWINCH , now exiting…; ’ SIGWINCH
trap 'echo recived SIGRTMIN+1 , now exiting…; ’ SIGRTMIN+1
trap 'echo recived SIGRTMIN+6 , now exiting…; ’ SIGRTMIN+6
trap 'echo recived SIGRTMIN+11 , now exiting…; ’ SIGRTMIN+11
trap 'echo recived SIGRTMAX-14 , now exiting…; ’ SIGRTMAX-14
trap 'echo recived SIGRTMAX-9 , now exiting…; ’ SIGRTMAX-9
trap 'echo recived SIGRTMAX-4 , now exiting…; ’ SIGRTMAX-4
trap 'echo recived SIGILL , now exiting…; ’ SIGILL
trap 'echo recived SIGKILL , now exiting…; ’ SIGKILL
trap 'echo recived SIGALRM , now exiting…; ’ SIGALRM
trap 'echo recived SIGSTOP , now exiting…; ’ SIGSTOP
trap 'echo recived SIGXCPU , now exiting…; ’ SIGXCPU
trap 'echo recived SIGIO , now exiting…; ’ SIGIO
trap 'echo recived SIGRTMIN+2 , now exiting…; ’ SIGRTMIN+2
trap 'echo recived SIGRTMIN+7 , now exiting…; ’ SIGRTMIN+7
trap 'echo recived SIGRTMIN+12 , now exiting…; ’ SIGRTMIN+12
trap 'echo recived SIGRTMAX-13 , now exiting…; ’ SIGRTMAX-13
trap 'echo recived SIGRTMAX-8 , now exiting…; ’ SIGRTMAX-8
trap 'echo recived SIGRTMAX-3 , now exiting…; ’ SIGRTMAX-3
trap 'echo recived SIGTRAP , now exiting…; ’ SIGTRAP
trap 'echo recived SIGUSR1 , now exiting…; ’ SIGUSR1
trap 'echo recived SIGTERM , now exiting…; ’ SIGTERM
trap 'echo recived SIGTSTP , now exiting…; ’ SIGTSTP
trap 'echo recived SIGXFSZ , now exiting…; ’ SIGXFSZ
trap 'echo recived SIGPWR , now exiting…; ’ SIGPWR
trap 'echo recived SIGRTMIN+3 , now exiting…; ’ SIGRTMIN+3
trap 'echo recived SIGRTMIN+8 , now exiting…; ’ SIGRTMIN+8
trap 'echo recived SIGRTMIN+13 , now exiting…; ’ SIGRTMIN+13
trap 'echo recived SIGRTMAX-12 , now exiting…; ’ SIGRTMAX-12
trap 'echo recived SIGRTMAX-7 , now exiting…; ’ SIGRTMAX-7
trap 'echo recived SIGRTMAX-2 , now exiting…; ’ SIGRTMAX-2
count=0

while :
do
sleep 1
count=$(expr $count + 1)
echo $count
done

#put it on background
nohup ./trap_test.sh > trap.log &

#restart service
systemctl restart teleport

#and login again , here is trap.log
hello
1
2
3
4
5
Terminated
recived SIGTERM , now exiting…
recived SIGCONT , now exiting…
recived SIGTERM , now exiting…
recived SIGCONT , now exiting…

1
2
3
4
5
6
7

70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89


seem nothing catched at proceess finally killed , and restart service cost much more time than ordinary

Can you show your systemd unit file?

here is my systemd unit file

cat /lib/systemd/system/teleport.service
[Unit]
Description=Teleport SSH Service
After=network.target

[Service]
Type=simple
Restart=on-failure
ExecStart=/usr/local/bin/teleport start --config=/etc/teleport/teleport.yaml --pid-file=/var/run/teleport.pid
ExecReload=/bin/kill -HUP $MAINPID
PIDFile=/var/run/teleport.pid
LimitNOFILE=655350

[Install]
WantedBy=multi-user.target

hello? anybody here ? :dizzy_face:

Sorry for the super late response, can you take a look at this thread and tell me whether setting KillMode solved your problem?

Thread links:


I add KillMode=process to [Service] section and that’s work!
thank you ~~ :+1:

1 Like

thank you too~
learned a lot from this 2 Thread :+1:

1 Like