Asyf has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I have a forked socket server with around 1000 child process running.
What could be the best way to restart the socket server by:
1 - Through the server coding. For example if the server receives the string "restart_the_server", then I need to stop all child process and restart the socket server.
2 - Through the command line linux/Ubuntu

Please help.

Replies are listed 'Best First'.
Re: Restarting Perl Socket Server
by huck (Prior) on Jan 10, 2018 at 07:40 UTC

    I use an init.d process devolved from https://github.com/mjsilva/rtorrent-screen-debian-init-script/blob/master/rtorrent via https://ubuntuforums.org/showthread.php?t=2231702. It allows me to sudo ... start|stop|restart

    #!/bin/bash ### BEGIN INIT INFO # Provides: huck-youtube monitor for lxle0 # Required-Start: $local_fs $remote_fs $network $syslog # Required-Stop: $local_fs $remote_fs $network $syslog # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: Start/stop youtube monitor daemon ### END INIT INFO # http://ubuntuforums.org/showthread.php?t=2231702 # https://github.com/mjsilva/rtorrent-screen-debian-init-script/blob/m +aster/rtorrent # sudo update-rc.d youhuckmon defaults 99 # sudo /etc/init.d/youhuckmon start MYLOG="/home/active/you-huck/apiv3/base/huck4you-startup.log.lst" echo `date` $1 >> $MYLOG ## Username to run under ## home directory of this user! USER="phuck" ## start with a cd here CDTO="/home/active/you-huck/apiv3" ## Absolute path to the binary. RUNME="/home/huck/cvs/you-perl/go-you-huck" ## Absolute path to the screen binary. SCREEN="/usr/bin/screen" ## Name of the screen session, you can then "screen -r <SCREEN_NAME>" +to get it back ## to the forground and work with it on your shell. SCREEN_NAME="youtubemon" # Absolute path to PID file. PIDFILE="/var/run/youtube-huck4you.pid" case "$1" in ## Start screen in the background. start) cd $CDTO echo "Starting screen $SCREEN_NAME" | tee -a $MYLOG start-stop-daemon --start --background --oknodo \ --pidfile "$PIDFILE" --make-pidfile \ --chuid $USER \ --chdir $CDTO \ --exec $SCREEN -- -DmUS $SCREEN_NAME $RUNME # --exec $SCREEN -- -LDmUS $SCREEN_NAME $RUNME if [[ $? -ne 0 ]]; then echo "Error: screen $SCREEN_NAME failed to start." | tee - +a $MYLOG exit 1 fi echo "screen $SCREEN_NAME started successfully. " | tee -a $MY +LOG ;; ## Stop . stop) echo "Stopping screen $SCREEN_NAME." | tee -a $MYLOG start-stop-daemon --stop --oknodo --pidfile "$PIDFILE" if [[ $? -ne 0 ]]; then echo "Error: failed to stop $SCREEN_NAME process." | tee - +a $MYLOG exit 1 fi echo "$SCREEN_NAME stopped successfully." | tee -a $MYLOG ;; ## Restart restart) "$0" stop sleep 1 "$0" start || exit 1 ;; ## Print usage information if the user gives an invalid option. *) echo "Usage: $0 [start|stop|restart]" exit 1 ;; esac
    it uses screen to capture the sysout and syserr.

    phuck is "production-huck" of course :)

Re: Restarting Perl Socket Server
by Asyf (Initiate) on Jan 10, 2018 at 06:00 UTC
    I started the socket server by Cron Job