-
Notifications
You must be signed in to change notification settings - Fork 0
/
notifier_php_builder.sh
executable file
·56 lines (43 loc) · 1.9 KB
/
notifier_php_builder.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/bin/bash
green_color='\e[0;32m'
red_color='\e[0;31m'
rest_color='\e[0m'
if [ ${USER} != "root" ]; then
sudo_prefix='sudo '
fi;
if [ ! -f phone.csv ]; then
echo -e "${red_color}phone.csv file is not found...${rest_color}"
exit 1;
fi;
if [ ! -f .env ]; then
echo -e "${red_color}.env file is not found...${rest_color}"
exit 1;
fi;
echo -e "${green_color}Creating a supervisor confiuration for notifier.php....${rest_color}"
supervisor_path='/etc/supervisor/conf.d/notifier-php.conf'
${sudo_prefix}touch ${supervisor_path}
echo '[program:notifier-php]' | ${sudo_prefix}tee ${supervisor_path}
echo "command=/bin/bash -c \"cd $PWD && /usr/bin/php7.4 notifier.php\"" | ${sudo_prefix}tee -a ${supervisor_path}
echo 'autostart=false' | ${sudo_prefix}tee -a ${supervisor_path}
echo 'autorestart=false' | ${sudo_prefix}tee -a ${supervisor_path}
echo 'startretries=0' | ${sudo_prefix}tee -a ${supervisor_path}
echo "user=$USER" | ${sudo_prefix}tee -a ${supervisor_path}
echo 'redirect_stderr=true' | ${sudo_prefix}tee -a ${supervisor_path}
echo "stdout_logfile=$PWD/notifier-php.log" | ${sudo_prefix}tee -a ${supervisor_path}
${sudo_prefix}systemctl restart supervisor
if [[ $? != 0 ]]; then
${sudo_prefix}rm -f ${supervisor_path}
echo -e "${red_color}The supervisor service is not found. Do you install it?${rest_color}"
exit 1;
fi;
echo "${yellow_color}Setting up the Cronjob...${rest_color}"
which crontab
if [[ $? != 0 ]]; then
echo -e "${red_color}The crontab is not found. Do you install it?${rest_color}"
exit 1;
fi;
cronjob_path="/etc/cron.d/notifier-php"
echo 'SHELL=/bin/bash' | ${sudo_prefix}tee ${cronjob_path}
echo 'PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin' | ${sudo_prefix}tee -a ${cronjob_path}
echo '* * * * * root supervisorctl start notifier-php' | ${sudo_prefix}tee -a ${cronjob_path}
echo -e "${green_color}Building PHP Notifier has been done!${rest_color}"