Re: issue with launching screen process with monit

"[email protected]" <[email protected]> Wed, 22 Oct 2025 13:05:51 +0200
Newsgroups gmane.comp.monitoring.monit.general
Message-ID <[email protected]>
--Apple-Mail=_3FCFBBDD-B5C8-41D4-AF11-433425511354
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain;
	charset=us-ascii

Hi Kacper,

it looks like a problem which was fixed in monit 5.35.0: The pidfile may =
contain a PID from the previous system boot, which belongs to a thread =
of different process after reboot.

Please can you upgrade monit? (5.35.2 recommended)

Best regards,
Martin



> On 22. 10. 2025, at 10:54, [email protected] wrote:
>=20
> Hi guys,=20
> I have a problem with the monit daemon on my ARM system. Once every =
5-6 times when I'm restarting the whole system, it happens that the =
screen process controlled by monit fails to start. I do not understand =
why. In monit logs or in system logs, there is no helpful information. =
Additionally, when monit claims that the process fails (and unmonitors =
it), I can see the proper screen process with a correct pid file =
available on the system. When I manually press "start service" in monit =
web gui, the correct process is found by monit. My monit version is =
5.34.3.
>=20
> I also do not understand how fast monit claims that the process fails =
to start and unmonitors it (in monit logs look like it takes 1-2 sec =
while timeout in monitrc for this process is 10 seconds).
>=20
> monitrc file:
> set daemon 20
> set onreboot start
> set log /var/log/monit.log
>=20
> check process screenprocess with pidfile /var/run/screenprocess.pid
>     if not exist then start
>     start program =3D "/etc/init.d/screenprocess start" with timeout =
10 seconds
>     stop program =3D "/etc/init.d/screenprocess stop" with timeout 10 =
seconds
>     if 5 restarts within 5 cycles then unmonitor
>=20
> screenprocess init.d script:
>=20
> #!/bin/sh
>=20
> PIDFILE=3D/var/run/screenprocess.pid
> SCREEN_PATH=3D/tmp/screen
>=20
> case "$1" in
>   start)
>     logger -t screenprocess "Starting ioc"
>     echo "Starting ioc"
>     if [ -f "$PIDFILE" ]; then
>       logger -t screenprocess "Screen process is already running."
>       echo "Screen process is already running."
>       exit 1
>     fi
>     # create dir for screen socket files
>     mkdir -p $SCREEN_PATH
>     chmod 700 $SCREEN_PATH
>     export SCREENDIR=3D$SCREEN_PATH
>     # set stack limit
>     ulimit -s 1024
>     # run screen
>     screen -c /etc/screenprocesslogs.conf -dmSL screenprocess =
./start.cmd && sleep 1
>     # get pid of screen
>     screen -ls | grep -oE "[0-9]+\.screenprocess" | sed -e =
"s/\..*$//g" | tail -n 1 > $PIDFILE
>     if [ -f "$PIDFILE" ]; then
>       NUM_PIDS=3D$(grep -E '^[0-9]+$' "$PIDFILE" | wc -l)
>       # check if only one screen session is active
>       if [ $NUM_PIDS -eq 1 ]; then
>         logger -t screenprocess "Screen process started successfully."
>         echo "Screen process started successfully."
>       else
>         logger -t screenprocess "Failed to start Screen process. =
Multiple PIDs or none detected"
>         echo "Failed to start Screen process. Multiple PIDs or none =
detected"
>         exit 1
>       fi
>     else
>       logger -t screenprocess "Failed to start Screen process. PID =
file $PIDFILE not created"
>       echo "Failed to start Screen process. PID file $PIDFILE not =
created"
>       exit 1
>     fi
>     ;;
>=20
>=20
> Logs from monit:
> [2025-10-22T08:27:22+0000] debug    : pidfile =
'/var/run/screenprocess.pid' does not exist
> [2025-10-22T08:27:22+0000] error    : 'screenprocess' process is not =
running
> [2025-10-22T08:27:22+0000] debug    : =
--------------------------------------------------------------------------=
-----
> [2025-10-22T08:27:22+0000] debug    : =
--------------------------------------------------------------------------=
-----
> [2025-10-22T08:27:22+0000] debug    : pidfile =
'/var/run/screenprocess.pid' does not exist
> [2025-10-22T08:27:22+0000] info     : 'screenprocess' start: =
'/etc/init.d/screenprocess start'
> [2025-10-22T08:27:22+0000] info     : 'mgmt' start on user request
> [2025-10-22T08:27:22+0000] info     : 'screenprocess' start on user =
request
> [2025-10-22T08:27:22+0000] info     : Monit daemon with PID 251 =
awakened
> [2025-10-22T08:27:23+0000] debug    : Starting screen process
> screen process started successfully.
> [2025-10-22T08:27:24+0000] error    : 'screenprocess' service =
restarted 5 times within 5 cycles(s) - unmonitor
>=20
> I'd be grateful for any tips on what can be wrong.
>=20
> Cheers
>=20
> Kacper
>=20
>=20
>=20


--Apple-Mail=_3FCFBBDD-B5C8-41D4-AF11-433425511354
Content-Transfer-Encoding: 7bit
Content-Type: text/html;
	charset=us-ascii

<html aria-label="message body"><head><meta http-equiv="content-type" content="text/html; charset=us-ascii"></head><body style="overflow-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;"><div>Hi Kacper,</div><div><br></div><div>it looks like a problem which was fixed in monit 5.35.0: The pidfile may contain a PID from the previous system boot, which belongs to a thread of different process after reboot.</div><div><br></div><div>Please can you upgrade monit? (5.35.2 recommended)</div><div><br></div><div>Best regards,</div><div>Martin</div><div><br></div><div><br></div><br><div><blockquote type="cite"><div>On 22. 10. 2025, at 10:54, [email protected] wrote:</div><div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px;"><br></
 div>

  

    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  
  <div><p>Hi guys,&nbsp;<br>
      I have a problem with the monit daemon on my ARM system. Once
      every 5-6 times when I'm restarting the whole system, it happens
      that the screen process controlled by monit fails to start. I do
      not understand why. In monit logs or in system logs, there is no
      helpful information. Additionally, when monit claims that the
      process fails (and unmonitors it), I can see the proper screen
      process with a correct pid file available on the system. When I
      manually press "start service" in monit web gui, the correct
      process is found by monit. My monit version is 5.34.3.</p><p>I also do not understand how fast monit claims that the process
      fails to start and unmonitors it (in monit logs look like it takes
      1-2 sec while timeout in monitrc for this process is 10 seconds).</p><p><b>monitrc file:</b><br>
      set daemon 20<br>
      set onreboot start<br>
      set log /var/log/monit.log<br>
      <br>
      check process screenprocess with pidfile
      /var/run/screenprocess.pid<br>
      &nbsp; &nbsp; if not exist then start<br>
      &nbsp; &nbsp; start program = "/etc/init.d/screenprocess start" with timeout
      10 seconds<br>
      &nbsp; &nbsp; stop program = "/etc/init.d/screenprocess stop" with timeout
      10 seconds<br>
      &nbsp; &nbsp; if 5 restarts within 5 cycles then unmonitor<br>
    </p><p><b>screenprocess init.d script:</b></p><p>#!/bin/sh<br>
      <br>
      PIDFILE=/var/run/screenprocess.pid<br>
      SCREEN_PATH=/tmp/screen<br>
      <br>
      case "$1" in<br>
      &nbsp; start)<br>
      &nbsp; &nbsp; logger -t screenprocess "Starting ioc"<br>
      &nbsp; &nbsp; echo "Starting ioc"<br>
      &nbsp; &nbsp; if [ -f "$PIDFILE" ]; then<br>
      &nbsp; &nbsp; &nbsp; logger -t screenprocess "Screen process is already running."<br>
      &nbsp; &nbsp; &nbsp; echo "Screen process is already running."<br>
      &nbsp; &nbsp; &nbsp; exit 1<br>
      &nbsp; &nbsp; fi<br>
      &nbsp; &nbsp; # create dir for screen socket files<br>
      &nbsp; &nbsp; mkdir -p $SCREEN_PATH<br>
      &nbsp; &nbsp; chmod 700 $SCREEN_PATH<br>
      &nbsp; &nbsp; export SCREENDIR=$SCREEN_PATH<br>
      &nbsp; &nbsp; # set stack limit<br>
      &nbsp; &nbsp; ulimit -s 1024<br>
      &nbsp; &nbsp; # run screen<br>
      &nbsp; &nbsp; screen -c /etc/screenprocesslogs.conf -dmSL screenprocess
      ./start.cmd &amp;&amp; sleep 1<br>
      &nbsp; &nbsp; # get pid of screen<br>
      &nbsp; &nbsp; screen -ls | grep -oE "[0-9]+\.screenprocess" | sed -e
      "s/\..*$//g" | tail -n 1 &gt; $PIDFILE<br>
      &nbsp; &nbsp; if [ -f "$PIDFILE" ]; then<br>
      &nbsp; &nbsp; &nbsp; NUM_PIDS=$(grep -E '^[0-9]+$' "$PIDFILE" | wc -l)<br>
      &nbsp; &nbsp; &nbsp; # check if only one screen session is active<br>
      &nbsp; &nbsp; &nbsp; if [ $NUM_PIDS -eq 1 ]; then<br>
      &nbsp; &nbsp; &nbsp; &nbsp; logger -t screenprocess "Screen process started
      successfully."<br>
      &nbsp; &nbsp; &nbsp; &nbsp; echo "Screen process started successfully."<br>
      &nbsp; &nbsp; &nbsp; else<br>
      &nbsp; &nbsp; &nbsp; &nbsp; logger -t screenprocess "Failed to start Screen process.
      Multiple PIDs or none detected"<br>
      &nbsp; &nbsp; &nbsp; &nbsp; echo "Failed to start Screen process. Multiple PIDs or
      none detected"<br>
      &nbsp; &nbsp; &nbsp; &nbsp; exit 1<br>
      &nbsp; &nbsp; &nbsp; fi<br>
      &nbsp; &nbsp; else<br>
      &nbsp; &nbsp; &nbsp; logger -t screenprocess "Failed to start Screen process. PID
      file $PIDFILE not created"<br>
      &nbsp; &nbsp; &nbsp; echo "Failed to start Screen process. PID file $PIDFILE not
      created"<br>
      &nbsp; &nbsp; &nbsp; exit 1<br>
      &nbsp; &nbsp; fi<br>
      &nbsp; &nbsp; ;;<br>
      <br>
    </p><p><b>Logs from monit:</b><br>
      [2025-10-22T08:27:22+0000] debug&nbsp; &nbsp; : pidfile
      '/var/run/screenprocess.pid' does not exist<br>
      [2025-10-22T08:27:22+0000] error&nbsp; &nbsp; : 'screenprocess' process is
      not running<br>
      [2025-10-22T08:27:22+0000] debug&nbsp; &nbsp; :
-------------------------------------------------------------------------------<br>
      [2025-10-22T08:27:22+0000] debug&nbsp; &nbsp; :
-------------------------------------------------------------------------------<br>
      [2025-10-22T08:27:22+0000] debug&nbsp; &nbsp; : pidfile
      '/var/run/screenprocess.pid' does not exist<br>
      [2025-10-22T08:27:22+0000] info&nbsp; &nbsp; &nbsp;: 'screenprocess' start:
      '/etc/init.d/screenprocess start'<br>
      [2025-10-22T08:27:22+0000] info&nbsp; &nbsp; &nbsp;: 'mgmt' start on user request<br>
      [2025-10-22T08:27:22+0000] info&nbsp; &nbsp; &nbsp;: 'screenprocess' start on
      user request<br>
      [2025-10-22T08:27:22+0000] info&nbsp; &nbsp; &nbsp;: Monit daemon with PID 251
      awakened<br>
      [2025-10-22T08:27:23+0000] debug&nbsp; &nbsp; : Starting screen process<br>
      screen process started successfully.<br>
      [2025-10-22T08:27:24+0000] error&nbsp; &nbsp; : 'screenprocess' service
      restarted 5 times within 5 cycles(s) - unmonitor<br>
    </p><p>I'd be grateful for any tips on what can be wrong.</p><p>Cheers</p><p>Kacper</p>
  </div>

<br><br></div></blockquote></div><br></body></html>
--Apple-Mail=_3FCFBBDD-B5C8-41D4-AF11-433425511354--