Script to restart playsms in cron?

I was wondering if anyone would share their script to restart playsms? I’m a php noobie.
I find playsms stops on its own sometimes and I don’t realize it.

Thanks, Bart

I am using supervisor to manage playsms. I can post my config script if you like.

I found this from Anton - seem to work

Well, that works too! I like supervisor because it restarts in realtime and also logs problems.

What does your script do - just wondering :slight_smile:

Hmm, that might be useful to know when restart was required

Bart

Supervisor is a process monitor on steroids. It can be installed using apt on ubuntu systems.

Here is the config for anyone who wants it.

supervisor.conf

; Note: shell expansion ("~" or "$HOME") is not supported.  Environment
; variables can be expanded using this syntax: "%(ENV_HOME)s".

[unix_http_server]
file=/tmp/supervisor.sock   ; (the path to the socket file)
;chmod=0700                 ; socket file mode (default 0700)
;chown=nobody:nogroup       ; socket file uid:gid owner
;username=user              ; (default is no username (open server))
;password=123               ; (default is no password (open server))

;[inet_http_server]         ; inet (TCP) server disabled by default
;port=127.0.0.1:9001        ; (ip_address:port specifier, *:port for all iface)
;username=user              ; (default is no username (open server))
;password=123               ; (default is no password (open server))

[supervisord]
logfile=/var/log/supervisord.log ; (main log file;default $CWD/supervisord.log)
logfile_maxbytes=150MB       ; (max main logfile bytes b4 rotation;default 50MB)
logfile_backups=10           ; (num of main logfile rotation backups;default 10)
loglevel=info               ; (log level;default info; others: debug,warn,trace)
pidfile=/tmp/supervisord.pid ; (supervisord pidfile;default supervisord.pid)
nodaemon=false               ; (start in foreground if true;default false)
minfds=1024                  ; (min. avail startup file descriptors;default 1024)
minprocs=200                 ; (min. avail process descriptors;default 200)
umask=022                    ; (process file creation umask;default 022)
user=root                    ; (default is current user, required if root)
;identifier=supervisor       ; (supervisord identifier, default is 'supervisor')
;directory=/tmp              ; (default is not to cd during start)
;nocleanup=true              ; (don't clean up tempfiles at start;default false)
;childlogdir=/tmp            ; ('AUTO' child log dir, default $TEMP)
;environment=KEY=value       ; (key value pairs to add to environment)
;strip_ansi=false            ; (strip ansi escape codes in logs; def. false)

; the below section must remain in the config file for RPC
; (supervisorctl/web interface) to work, additional interfaces may be
; added by defining them in separate rpcinterface: sections
[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface

[supervisorctl]
serverurl=unix:///tmp/supervisor.sock ; use a unix:// URL  for a unix socket
;serverurl=http://127.0.0.1:9001 ; use an http:// url to specify an inet socket
;username=chris              ; should be same as http_username if set
;password=123                ; should be same as http_password if set
;prompt=mysupervisor         ; cmd line prompt (default "supervisor")
;history_file=~/.sc_history  ; use readline history if available

; The below sample program section shows all possible program subsection values,
; create one or more 'real' program: sections to be able to control them under
; supervisor.

[program:playsms_sendsmsd]
command=/usr/bin/php -q /usr/local/bin/playsmsd /etc/playsmsd.conf sendsmsd ; the program (relative uses PATH, can take args)
numprocs=1                    ; number of processes copies to start (def 1)
autostart=true                ; start at supervisord start (default: true)
autorestart=true        ; whether/when to restart (default: unexpected)

[program:playsms_recvsmsd]
command=/usr/bin/php -q /usr/local/bin/playsmsd /etc/playsmsd.conf recvsmsd ; the program (relative uses PATH, can take args)
numprocs=1                    ; number of processes copies to start (def 1)
autostart=true                ; start at supervisord start (default: true)
autorestart=true        ; whether/when to restart (default: unexpected)

[program:playsms_dlrssmsd]
command=/usr/bin/php -q /usr/local/bin/playsmsd /etc/playsmsd.conf dlrssmsd ; the program (relative uses PATH, can take args)
numprocs=1                    ; number of processes copies to start (def 1)
autostart=true                ; start at supervisord start (default: true)
autorestart=true        ; whether/when to restart (default: unexpected)

[program:playsms_schedule]
command=/usr/bin/php -q /usr/local/bin/playsmsd /etc/playsmsd.conf schedule ; the program (relative uses PATH, can take args)
numprocs=1                    ; number of processes copies to start (def 1)
autostart=true                ; start at supervisord start (default: true)
autorestart=true        ; whether/when to restart (default: unexpected)

Trying now

Thanks, Bart

Note that this script is dependent on where your php is installed. it’s either /usr/bin/php or /usr/local/bin/php (usually the former).

Hi,

playsmsd watchdog (or playsmsd /etc/playsmsd.conf watchdog in 1.3+) is exactly the same as playsmsd start. I rename it to watchdog on cron so that you guys encouraged to use that, if I use start you will start asking question about duplication :smile: (ref: https://github.com/antonraharja/playSMS/blob/master/daemon/linux/bin/playsmsd.php#L296-L303)

the start command will try to check whether daemons up and running, if there is daemon that is crashed playsmsd will start it

running the start command multiple times (or now you know its the same thing as playsmsd watchdog) will not make daemons started multiple time, so far it is safe to do so, therefore I put it on crontab every 10 minutes. you can set to run in every 1 minute (anti-duplicate: https://github.com/antonraharja/playSMS/blob/master/daemon/linux/bin/playsmsd.php#L91-L95)

using supervisor is better as it has better start-stop control and assurance that no daemon duplicated

anton