-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_service.in
849 lines (835 loc) · 26.3 KB
/
create_service.in
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
#!/bin/sh
#
# $Id: create_service.in,v 1.64 2024-11-15 09:26:18+05:30 Cprogrammer Exp mbhangui $
#
check_update_if_diff()
{
val=`cat $1 2>/dev/null`
if [ ! " $val" = " $2" ] ; then
echo $2 > $1
fi
}
get_mpd_conf_value()
{
grep "^$1" @sysconfdir@/mpd.conf|awk '{print $2}' | \
sed -e 's{"{{g'
}
add_service()
{
if [ "$service_name" = "fclient" -o "$service_name" = "fserver" ] ; then
if [ $# -ne 3 ] ; then
usage
fi
host=$1
port=$2
userid=$3
elif [ "$service_name" = "update" ] ; then
if [ $# -ne 1 ] ; then
usage
fi
userid=$1
elif [ "$service_name" = "rsync" -a $# -ne 0 ] ; then
usage
fi
case "$SYSTEM" in
Linux)
user=$(getent passwd $userid)
status=$?
if [ $status -ne 0 ] ; then
if [ $status -eq 2 ] ; then
echo "No such userid $userid" 1>&2
else
echo "failed to get information for user $userid" 1>&2
fi
return 1
else
user=$(echo $user|cut -d: -f1)
fi
;;
Darwin)
user=$(dscl . -list /Users UniqueID|grep -w $userid|awk '{print $1}')
if [ -z "$user" ] ; then
echo "No such userid $userid" 1>&2
return 1
fi
;;
*)
echo "Configure/setup startup manually" 1>&2
exit 1
;;
esac
if [ -z "$servicedir" ] ; then
echo "--servicedir not specified" 1>&2
exit 1
fi
if [ ! -d $logdir ] ; then
mkdir -p $logdir
chown qmaill:nofiles $logdir
fi
if [ "$service_name" = "rsync" ] ; then
service_name="$service_name.875"
fi
mkdir -p $servicedir/$service_name/log
mkdir -p $servicedir/$service_name/variables
echo "$prog_args" > $servicedir/$service_name/variables/.options
(
echo "#!/bin/sh"
echo "exec /usr/bin/setuidgid qmaill \\"
if [ -f /usr/sbin/multilog ] ; then
echo "/usr/sbin/multilog t $logdir/$service_name"
else
echo "/usr/bin/multilog t $logdir/$service_name"
fi
) > $servicedir/$service_name/log/run
chmod +x $servicedir/$service_name/log/run
case "$SYSTEM" in
Linux)
home=$(getent passwd $user|cut -d: -f6)
;;
Darwin)
home=$(dscl . -list /Users NFSHomeDirectory|grep $user|awk '{print $2}')
;;
esac
if [ -n "$home" ] ; then
if [ "$service_name" = "fclient" ] ; then
check_update_if_diff $servicedir/$service_name/variables/PATH "/bin:/usr/bin:@prefix@/bin:$home/.pistop:/usr/local/bin:/opt/local/bin:/sbin:/usr/sbin"
check_update_if_diff $servicedir/$service_name/variables/HOME "$home"
elif [ "$service_name" = "update" ] ; then
check_update_if_diff $servicedir/$service_name/variables/HOME "$home"
fi
elif [ "$service_name" = "fclient" -o "$service_name" = "update" ] ; then
echo "failed to get home for $user" 1>&2
return 1
fi
if [ "$service_name" != "rsync" ] ; then
case "$SYSTEM" in
Linux)
t_uid=$(getent passwd $user|cut -d: -f3)
t_gid=$(getent passwd $user|cut -d: -f4)
if [ -z "$t_uid" -o -z "$t_gid" ] ; then
echo "failed to get uid/gid for $user" 1>&2
return 1
fi
;;
Darwin)
t_uid=$(dscl . -read /Users/$user UniqueID|cut -d: -f2|sed 's{ {{g')
t_gid=$(dscl . -read /Users/$user PrimaryGroupID|cut -d: -f2|sed 's{ {{g')
if [ -z "$t_uid" -o -z "$t_gid" ] ; then
echo "failed to get uid/gid for $user" 1>&2
return 1
fi
;;
esac
fi
if [ "$service_name" = "fclient" ] ; then
mkdir -p $home/.pistop
for i in pistopstart
do
if [ ! -f $home/.pistop/$i ] ; then
cp @pistoplibexecdir@/$i $home/.pistop
elif [ ! -f $home/.pistop/."$i".nooverwrite ] ; then
cp @pistoplibexecdir@/$i $home/.pistop
fi
done
chown -R $t_uid:$t_gid $home/.pistop
check_update_if_diff $servicedir/$service_name/variables/HOST $host
check_update_if_diff $servicedir/$service_name/variables/PORT $port
if [ -n "$lcdfifo" ] ; then
> $servicedir/$service_name/variables/LCD_HOST
> $servicedir/$service_name/variables/LCD_PORT
check_update_if_diff $servicedir/$service_name/variables/LCD_FIFO $lcdfifo
elif [ -n "$lcdhost" -a -n "$lcdport" ] ; then
> $servicedir/$service_name/variables/LCD_FIFO
check_update_if_diff $servicedir/$service_name/variables/LCD_HOST $lcdhost
check_update_if_diff $servicedir/$service_name/variables/LCD_PORT $lcdport
else
> $servicedir/$service_name/variables/LCD_FIFO
> $servicedir/$service_name/variables/LCD_HOST
> $servicedir/$service_name/variables/LCD_PORT
fi
if [ -n "$notifyfifo" ] ; then
> $servicedir/$service_name/variables/NOTIFY_HOST
> $servicedir/$service_name/variables/NOTIFY_PORT
check_update_if_diff $servicedir/$service_name/variables/NOTIFY_FIFO $notifyfifo
elif [ -n "$notifyhost" -a -n "$notifyport" ] ; then
> $servicedir/$service_name/variables/LCD_FIFO
check_update_if_diff $servicedir/$service_name/variables/NOTIFY_HOST $notifyhost
check_update_if_diff $servicedir/$service_name/variables/NOTIFY_PORT $notifyport
else
> $servicedir/$service_name/variables/NOTIFY_FIFO
> $servicedir/$service_name/variables/NOTIFY_HOST
> $servicedir/$service_name/variables/NOTIFY_PORT
fi
check_update_if_diff $servicedir/$service_name/variables/TIMEOUT 60
check_update_if_diff $servicedir/$service_name/variables/MAXDAEMONS 10
check_update_if_diff $servicedir/$service_name/variables/USER "root"
check_update_if_diff $servicedir/$service_name/variables/HOME $home
if [ -n "$MDRIVE" ] ; then
check_update_if_diff $servicedir/$service_name/variables/MDRIVE $MDRIVE
if [ -d $MDRIVE/backup ] ; then
check_update_if_diff $servicedir/$service_name/variables/DEST "$MDRIVE"
fi
else
> $servicedir/$service_name/variables/MDRIVE
fi
elif [ "$service_name" = "fserver" ] ; then
mkdir -p $home/.pistop
for i in pistopstart
do
if [ ! -f $home/.pistop/$i ] ; then
cp @pistoplibexecdir@/$i $home/.pistop
elif [ ! -f $home/.pistop/."$i".nooverwrite ] ; then
cp @pistoplibexecdir@/$i $home/.pistop
fi
done
chown -R $t_uid:$t_gid $home/.pistop
# HOST PORT USER MAXDAEMONS MDRIVE
check_update_if_diff $servicedir/$service_name/variables/HOST $host
check_update_if_diff $servicedir/$service_name/variables/PORT $port
if [ -n "$lcdfifo" ] ; then
> $servicedir/$service_name/variables/LCD_HOST
> $servicedir/$service_name/variables/LCD_PORT
check_update_if_diff $servicedir/$service_name/variables/LCD_FIFO $lcdfifo
elif [ -n "$lcdhost" -a -n "$lcdport" ] ; then
> $servicedir/$service_name/variables/LCD_FIFO
check_update_if_diff $servicedir/$service_name/variables/LCD_HOST $lcdhost
check_update_if_diff $servicedir/$service_name/variables/LCD_PORT $lcdport
else
> $servicedir/$service_name/variables/LCD_FIFO
> $servicedir/$service_name/variables/LCD_HOST
> $servicedir/$service_name/variables/LCD_PORT
fi
if [ -n "$notifyfifo" ] ; then
> $servicedir/$service_name/variables/NOTIFY_HOST
> $servicedir/$service_name/variables/NOTIFY_PORT
check_update_if_diff $servicedir/$service_name/variables/NOTIFY_FIFO $notifyfifo
elif [ -n "$notifyhost" -a -n "$notifyport" ] ; then
> $servicedir/$service_name/variables/NOTIFY_FIFO
check_update_if_diff $servicedir/$service_name/variables/NOTIFY_HOST $notifyhost
check_update_if_diff $servicedir/$service_name/variables/NOTIFY_PORT $notifyport
else
> $servicedir/$service_name/variables/NOTIFY_FIFO
> $servicedir/$service_name/variables/NOTIFY_HOST
> $servicedir/$service_name/variables/NOTIFY_PORT
fi
check_update_if_diff $servicedir/$service_name/variables/MAXDAEMONS 10
check_update_if_diff $servicedir/$service_name/variables/USER "$user"
check_update_if_diff $servicedir/$service_name/variables/UID "$t_uid"
check_update_if_diff $servicedir/$service_name/variables/GID "$t_gid"
if [ -n "$MDRIVE" ] ; then
check_update_if_diff $servicedir/$service_name/variables/MDRIVE $MDRIVE
if [ -d $MDRIVE/backup ] ; then
check_update_if_diff $servicedir/$service_name/variables/DEST "$MDRIVE"
fi
else
> $servicedir/$service_name/variables/MDRIVE
fi
elif [ "$service_name" = "rsync.875" ] ; then
if [ "$SYSTEM" != "Linux" ] ; then
echo "$SYSTEM not supported" 1>&2
exit 1
fi
check_update_if_diff $servicedir/$service_name/variables/LOCALIP 0
check_update_if_diff $servicedir/$service_name/variables/MAXDAEMONS 10
check_update_if_diff $servicedir/$service_name/variables/MAXPERIP 4
check_update_if_diff $servicedir/$service_name/variables/PORT 875
check_update_if_diff $servicedir/$service_name/variables/SOFT_MEM 26214400
elif [ "$service_name" = "update" ] ; then
if [ "$SYSTEM" != "Linux" ] ; then
echo "$SYSTEM not supported" 1>&2
exit 1
fi
if [ ! -f $servicedir/$service_name/variables/UPGRADE ] ; then
check_update_if_diff $servicedir/$service_name/variables/UPGRADE \
"ucspi-tcp mpdev libqmail libdkim2 libsrs2 indimail-mini daemontools pistop mpd" \
"upmpdcli upmpdcli-config upmpdcli-radios libnpupnp1 libnpupnp1-dev libupnpp6" \
"libupnpp6-dev raspotify"
fi
if [ ! -f $servicedir/$service_name/variables/INTERVAL ] ; then
check_update_if_diff $servicedir/$service_name/variables/INTERVAL 21600
fi
check_update_if_diff $servicedir/$service_name/variables/DEBIAN_FRONTEND "noninteractive"
check_update_if_diff $servicedir/$service_name/variables/HOME $home
# the at command will use LOGNAME as the mail recipient
check_update_if_diff $servicedir/$service_name/variables/LOGNAME $user
# Create Maildir for receiving mail
if [ ! -d $home/Malidir ] ; then
mkdir -p $home/Maildir/new
mkdir -p $home/Maildir/cur
mkdir -p $home/Maildir/tmp
chown -R $t_uid:$t_gid $home/Maildir
fi
if [ -f /usr/sbin/qmail-direct ] ; then
flag=0
if [ ! -d $home/.defaultqueue ] ; then
flag=1
mkdir -p $home/.defaultqueue
fi
if [ ! -f $home/.defaultqueue/QMAILQUEUE ] ; then
flag=1
check_update_if_diff $home/.defaultqueue/QMAILQUEUE "/usr/sbin/qmail-direct"
fi
if [ ! -f $home/.defaultqueue/QUEUE_BASE ] ; then
flag=1
check_update_if_diff $home/.defaultqueue/QUEUE_BASE $home"/Maildir"
fi
if [ ! -f $home/.defaultqueue/USER ] ; then
flag=1
check_update_if_diff $home/.defaultqueue/USER $user
fi
if [ $flag -eq 1 ] ; then
chown -R $t_uid:$t_gid $home/.defaultqueue
fi
fi
if [ -f /usr/sbin/qmail-direct -a -d /lib/systemd/system -a ! -d /lib/systemd/system/atd.service.d ] ; then
mkdir -p /lib/systemd/system/atd.service.d
(
echo "[Service]"
echo "EnvironmentFile=$servicedir/update/variables/.variables"
) > /lib/systemd/system/atd.service.d/override.conf
systemctl daemon-reload
fi
fi
# create /service/$service_name/run and /sevice/$service_name/log/run
if [ "$service_name" = "fclient" ] ; then
(
echo "#!/bin/bash"
echo "# $prog_args"
echo ""
echo "exec 2>&1"
echo
echo "for i in pistopstart"
echo "do"
echo " if [ -f \$HOME/.pistop/.\$i.nooverwrite ] ; then"
echo " continue"
echo " fi"
echo " diff @pistoplibexecdir@/\$i \$HOME/.pistop/\$i > /dev/null 2>&1"
echo " if [ \$? -ne 0 ] ; then"
echo " cp @pistoplibexecdir@/\$i \$HOME/.pistop/\$i"
echo " fi"
echo "done"
echo
echo "echo \"Started fclient service\""
echo "while true"
echo "do"
echo " bash -c \"</dev/tcp/\$HOST/\$PORT\" 2>/dev/null"
echo " if [ \$? -eq 0 ] ; then"
echo " echo \"\$HOST:\$PORT is alive\""
echo " exec /usr/bin/envdir variables /usr/bin/setuidgid \$USER \\"
echo " /usr/bin/tcpclient -vDHR -t \$TIMEOUT \$HOST \$PORT \\"
echo " @pistoplibexecdir@/pistopclient 2>&1"
echo " else"
echo " echo \"\$HOST:\$PORT is down. Sleeping for 30 seconds...\""
echo " sleep 30"
echo " fi"
echo "done"
) > $servicedir/$service_name/run
chmod +x $servicedir/$service_name/run
(
echo "#!/bin/sh"
echo "exec 2>&1"
echo "killall pistopstart"
echo "sleep 1"
echo "if [ -x \$HOME/.pistop/pistopstart ] ; then"
echo " exec envdir variables env POWER_OFF=\"\" setuidgid \$USER \\"
echo " \$HOME/.pistop/pistopstart stop"
echo "else"
echo " exec envdir variables env POWER_OFF=\"\" setuidgid \$USER \\"
echo " @pistoplibexecdir@/pistopstart stop"
echo "fi"
) > $servicedir/$service_name/shutdown
chmod +x $servicedir/$service_name/shutdown
echo 1 > $servicedir/$service_name/variables/FORCE_UMOUNT
if [ ! -f $servicedir/$service_name/variables/POWER_OFF ] ; then
> $servicedir/$service_name/variables/POWER_OFF
fi
elif [ "$service_name" = "fserver" ] ; then
(
echo "#!/bin/sh"
echo "# $prog_args"
echo ""
echo "exec 2>&1"
echo ""
echo "@pistoplibexecdir@/backup"
echo "if [ -x $MDRIVE/bin/boot_sound ] ; then"
echo " $MDRIVE/bin/boot_sound >/dev/null 2>&1"
echo "fi"
echo "systemctl status mpd >/dev/null 2>&1"
echo "if [ \$? -ne 0 ] ; then"
echo " systemctl start mpd"
echo "fi"
echo ""
echo "@pistoplibexecdir@/host_status \\\"3 0 3:\$(uname -n) PowerOn\\\""
echo ""
echo "exec /usr/bin/tcpserver -vDHRo -l 0 \\"
echo " -c variables/MAXDAEMONS -b \$MAXDAEMONS \\"
echo " -u \$UID -g \$GID \$HOST \$PORT \\"
echo "@pistoplibexecdir@/pistopserver"
) > $servicedir/$service_name/run
chmod +x $servicedir/$service_name/run
(
echo "#!/bin/sh"
echo "killall @pistoplibexecdir@/pistopserver"
echo "exit 0"
) > $servicedir/$service_name/shutdown
chmod +x $servicedir/$service_name/shutdown
elif [ "$service_name" = "rsync.875" ] ; then
(
echo "#!/bin/sh"
echo "# $prog_args"
echo ""
echo "exec 2>&1"
echo
echo "exec /usr/bin/softlimit -m \$SOFT_MEM -o 1024 \\"
echo " /usr/bin/tcpserver -vHRo -l \$LOCALIP \\"
echo " -c ./variables/MAXDAEMONS -C \$MAXPERIP -b \$MAXDAEMONS \\"
echo " \$LOCALIP \$PORT /usr/bin/rsync -v --daemon --no-detach --log-file=/dev/fd/2"
) > $servicedir/$service_name/run
chmod +x $servicedir/$service_name/run
touch $servicedir/$service_name/down
elif [ "$service_name" = "update" ] ; then
if [ -f /etc/debian_version ] ; then
system="debian"
elif [ -f /usr/bin/dnf ] ; then
system="rpm-dnf"
elif [ -f /usr/bin/yum ] ; then
system="rpm-yum"
elif [ -f /usr/bin/zypper ] ; then
system="rpm-suse"
else
system="unknown"
echo "unsupported system. Did not find apt-get, dnf, yum or zypper" 1>&2
exit 0
fi
(
echo "#!/bin/sh"
echo "# $prog_args"
echo ""
echo "exec 2>&1"
echo
echo "echo \"Check update after 5 minutes\""
echo "sleep 300"
echo "if [ -f variables/UPGRADE ] ; then"
echo " UPDATE=\$(cat variables/UPGRADE)"
echo "fi"
echo "if [ ! -x /usr/bin/at ] ; then"
echo " echo \\\"at command not found. Will not upgrade daemontools\\\""
echo " UPDATE=\$(cat variables/UPGRADE|sed -e 's{daemontools{{g')"
echo "fi"
echo "if [ -d $servicedir/fserver ] ; then"
echo " count=\$(ps -ef|grep @pistoplibexecdir@/pistopserver|egrep -v \"tcpserver|grep\"|wc -l)"
echo " if [ \$count -gt 0 ] ; then"
echo " echo \\\"\$count clients already running. Will not upgrade pistop, daemontools\\\""
echo " UPDATE=\$(cat variables/UPGRADE|sed -e 's{pistop{{g' -e 's{daemontools{{g')"
echo " fi"
echo "fi"
echo "exec /usr/bin/envdir variables sh -c \""
echo " echo \\\"starting update service\\\""
echo " if [ -n \\\"\$UPDATE\\\" ] ; then"
echo " echo \\\"checking updates for \$UPDATE\\\""
case "$system" in
debian)
check_update_if_diff $servicedir/$service_name/variables/DEBIAN_FRONTEND "noninteractive"
echo " env DEBIAN_FRONTEND=noninteractive apt-get -qy update"
echo " list=\\\$(apt list --upgradable \$UPDATE|grep -v List|wc -l)"
;;
rpm-dnf)
echo " dnf makecache --timer"
echo " dnf check-update \$UPDATE >/dev/null 2>&1"
echo " if [ \\\$? -ne 100 ] ; then"
echo " list=\\\"\\\""
echo " else"
echo " list=\\\"upgrade\\\""
echo " fi"
;;
rpm-yum)
echo " yum makecache --timer"
echo " yum check-update \$UPDATE >/dev/null 2>&1"
echo " if [ \\\$? -ne 100 ] ; then"
echo " list=\\\"\\\""
echo " else"
echo " list=\\\"upgrade\\\""
echo " fi"
;;
rpm-suse)
echo " zypper refresh"
echo " list=\\\$(zypper list-updates \$UPDATE|grep -v List|wc -l)"
;;
esac
echo " if [ -z \\\"\\\$list\\\" -o \\\"\\\$list\\\" -eq 0 ] ; then"
echo " echo \\\"no upgrade found\\\""
echo " elif [ -x /usr/bin/at ] ; then"
case "$system" in
debian)
echo -n " echo \\\"env DEBIAN_FFRONTEND=noninteractive apt-get "
echo "-qy --only-upgrade install \$UPDATE\\\"|at now +1 minute"
;;
rpm-dnf)
echo " echo \\\"dnf update \$UPDATE\\\"|at now +1 minute"
;;
rpm-yum)
echo " echo \\\"yum update \$UPDATE\\\"|at now +1 minute"
;;
rpm-suse)
echo " echo \\\"zypper up \$UPDATE\\\"|at now +1 minute"
;;
esac
echo " else"
case "$system" in
debian)
echo " env DEBIAN_FFRONTEND=noninteractive apt-get -qy --only-upgrade install \$UPDATE"
;;
rpm-dnf)
echo " dnf update \$UPDATE"
;;
rpm-yum)
echo " yum update \$UPDATE"
;;
rpm-suse)
echo " zypper up \$UPDATE"
;;
esac
echo " fi"
echo " fi"
echo " if [ -n \\\"\\\$INTERVAL\\\" -a \\\$INTERVAL -gt 600 ] ; then"
echo " echo \\\"sleeping for \\\$(expr \\\$INTERVAL / 3600) hr\\\""
echo " exec sleep \\\$INTERVAL"
echo " else"
echo " echo \\\"sleeping for 10 min\\\""
echo " exec sleep 600"
echo " fi"
echo "\""
) > $servicedir/$service_name/run
chmod +x $servicedir/$service_name/run
fi
}
del_service()
{
if [ ! -d $servicedir/$service_name ] ; then
return 0
fi
mv $servicedir/$service_name $servicedir/."$service_name"
svc -dx $servicedir/."$service_name" $servicedir/."$service_name"/log > /dev/null
sleep 5
/bin/rm -rf $servicedir/."$service_name" $servicedir/."$service_name"/log > /dev/null
}
usage()
{
(
echo "USAGE: create_service --servicedir=path\\"
echo " --service_name=fclient|fserver\\"
echo " --user=username --host=host --port=port\\"
echo " --lcdhost=host --lcdport=port || --lcdfifo=fifo\\"
echo " --notifyhost=host --notifyport=port || --notifyfifo=fifo\\"
echo " --mdrive=mpd drive\\"
echo " --add-service"
echo " or"
echo "USAGE: create_service --servicedir=path\\"
echo " --service_name=update --add-service"
echo " or"
echo "USAGE: create_service --servicedir=path\\"
echo " --service_name=rsync --host=host --port=port\\"
echo " --add-service"
) 1>&2
exit 1
}
################################# Main ##################################
if test $# -eq 0; then
usage
fi
ID=$(id -u)
if [ $ID -ne 0 ] ; then
echo "You are not root" 1>&2
exit 1
fi
logdir=/var/log/svc
servicedir=@servicedir@
user=""
lcdhost=""
lcdport=""
lcdfifo=""
notifyhost=""
notifyport=""
notifyfifo=""
prog_args="$0 $*"
SYSTEM=$(uname -s)
MDRIVE=""
RCSID="# \$Id: create_service.in,v 1.64 2024-11-15 09:26:18+05:30 Cprogrammer Exp mbhangui $"
[ -f /etc/mpd.conf ] && music_dir=$(get_mpd_conf_value music_dir) || music_dir=""
while test $# -gt 0; do
case "$1" in
-*=*) optarg=`echo "$1" | sed 's/[-_a-zA-Z0-9]*=//'`
;;
*) optarg=
;;
esac
case "$1" in
--servicedir=*)
servicedir=$optarg
;;
--service_name=*)
service_name=$optarg
if [ "$service_name" != "fclient" -a "$service_name" != "fserver" -a "$service_name" != "update" -a "$service_name" != "rsync" ] ; then
echo "service_name should be fclient, fserver, rsync or update" 1>&2
fi
;;
--mdrive=*)
MDRIVE=$optarg
;;
--user=*)
user=$optarg
;;
--host=*)
host=$optarg
;;
--port=*)
port=$optarg
;;
--lcdhost=*)
lcdhost=$optarg
;;
--lcdport=*)
lcdport=$optarg
;;
--lcdfifo=*)
lcdfifo=$optarg
;;
--notifyhost=*)
notifyhost=$optarg
;;
--notifyport=*)
notifyport=$optarg
;;
--notifyfifo=*)
notifyfifo=$optarg
;;
--add-service)
if [ -z "$servicedir" -o -z "$service_name" ] ; then
echo "You must specify servicedir, service_name" 1>&2
usage 1
elif [ "$service_name" = "fclient" -o "$service_name" = "fserver" ] ; then
if [ -z "$port" -o -z "$host" ] ; then
echo "You must specify port, host for $service_name" 1>&2
usage 1
fi
if [ -z "$MDRIVE" ] ; then
[ -n "$music_dir" ] && MDRIVE=$(dirname $music_dir) || MDRIVE=""
if [ -z "$MDRIVE" ] ; then
echo "MDRIVE not set for $service_name" 1>&2
usage 1
fi
fi
elif [ "$service_name" != "rsync" -a -z "$user" ] ; then
echo "UNIX user not specified" 1>&2
usage 1
fi
add_service $host $port $user
;;
--del-service)
del_service
;;
*)
echo "invalid option [$1]"
read key
usage
;;
esac
shift
done
#
# $Log: create_service.in,v $
# Revision 1.64 2024-11-15 09:26:18+05:30 Cprogrammer
# changes for latest daemontools 1.1.6
#
# Revision 1.63 2024-11-10 00:53:04+05:30 Cprogrammer
# remove POWER_OFF variable during shutdown
#
# Revision 1.62 2024-11-10 00:11:52+05:30 Cprogrammer
# redirect errors to log
#
# Revision 1.61 2024-10-25 16:39:17+05:30 Cprogrammer
# fixed setting of HOME, USER in shutdown script
#
# Revision 1.60 2024-04-21 23:12:22+05:30 Cprogrammer
# added desktop notification to notifyhost or notify-fifo
#
# Revision 1.59 2024-03-21 23:42:08+05:30 Cprogrammer
# work without mpd
# create FORCE_UMOUNT variable
#
# Revision 1.58 2024-03-14 16:35:21+05:30 Cprogrammer
# added more packages to UPGRADE env variable
#
# Revision 1.57 2023-06-30 17:20:43+05:30 Cprogrammer
# added --lcdhost argument
#
# Revision 1.56 2023-06-29 17:37:17+05:30 Cprogrammer
# added --lcdhost, --lcdport to create LCD_HOST, LCD_PORT env variables
#
# Revision 1.55 2023-06-28 12:33:28+05:30 Cprogrammer
# updated shutodwn to execute $HOME/.pistop/pistopstart
#
# Revision 1.54 2023-05-18 09:07:47+05:30 Cprogrammer
# kill pistopstart script if running in shutdown
#
# Revision 1.53 2023-05-18 08:16:00+05:30 Cprogrammer
# copy pistopstart to $HOME/.pistop for fserver too
#
# Revision 1.52 2022-12-27 10:35:54+05:30 Cprogrammer
# updated for change in tcpclient -n option
#
# Revision 1.51 2022-07-13 22:49:53+05:30 Cprogrammer
# suppress error for backup dir if MDrive is not mounted
#
# Revision 1.50 2022-07-13 17:15:40+05:30 Cprogrammer
# added /sbin, /usr/sbin to PATH
# skip setting env variables when running /service/fclient/shutdown
#
# Revision 1.49 2022-07-12 17:24:26+05:30 Cprogrammer
# added MDRIVE env variable
#
# Revision 1.48 2022-07-03 12:22:44+05:30 Cprogrammer
# pass -n "" for fclient to use un-encrypted channel
#
# Revision 1.47 2022-06-30 16:38:52+05:30 Cprogrammer
# fixed bugs
#
# Revision 1.46 2022-06-30 15:42:28+05:30 Cprogrammer
# version 2.0 of create_service
#
# Revision 1.45 2022-06-28 19:08:41+05:30 Cprogrammer
# use variables set in configure.ac
#
# Revision 1.44 2022-06-28 14:01:53+05:30 Cprogrammer
# use variables set by configure.ac
#
# Revision 1.43 2022-04-30 11:11:16+05:30 Cprogrammer
# removed call to backup in run script
#
# Revision 1.42 2022-02-14 10:07:18+05:30 Cprogrammer
# make fclient run script silent
#
# Revision 1.41 2021-10-09 23:51:40+05:30 Cprogrammer
# play boot sound in fserver script
#
# Revision 1.40 2021-09-24 11:40:29+05:30 Cprogrammer
# create shutdown script to unmount MDrive
#
# Revision 1.39 2021-06-16 19:14:13+05:30 Cprogrammer
# added rsync service
#
# Revision 1.38 2021-06-06 11:04:16+05:30 Cprogrammer
# sleep after backup
#
# Revision 1.37 2021-05-07 13:12:11+05:30 Cprogrammer
# skip updating UPGRADE, INTERVAL env variables
#
# Revision 1.36 2021-05-06 13:34:21+05:30 Cprogrammer
# skip daemontools if clients are connected to fserver service
#
# Revision 1.35 2021-05-05 13:35:32+05:30 Cprogrammer
# added logging statements
#
# Revision 1.34 2021-05-02 19:21:19+05:30 Cprogrammer
# fixed update not getting skipped when no updates available
#
# Revision 1.33 2021-05-02 17:38:49+05:30 Cprogrammer
# fix for atd override.conf
#
# Revision 1.32 2021-05-02 10:06:07+05:30 Cprogrammer
# create env variables for atd service for mail to work using qmail-direct
#
# Revision 1.31 2021-05-01 20:37:40+05:30 Cprogrammer
# refactored code for update service
#
# Revision 1.30 2021-05-01 14:55:28+05:30 Cprogrammer
# create QUEUE_BASE env variable
#
# Revision 1.29 2021-05-01 13:15:37+05:30 Cprogrammer
# reworked service creation for update service
#
# Revision 1.28 2021-04-30 21:37:14+05:30 Cprogrammer
# fixed QMAILQUEUE for root user
#
# Revision 1.27 2021-04-30 12:17:36+05:30 Cprogrammer
# reworked update script
#
# Revision 1.26 2021-04-29 23:05:50+05:30 Cprogrammer
# create Maildir for mail delivery
#
# Revision 1.25 2021-04-27 22:23:40+05:30 Cprogrammer
# do initial sleep of 5 minutes for network to be up
#
# Revision 1.24 2021-04-27 19:07:25+05:30 Cprogrammer
# refactored code to make it smaller
#
# Revision 1.23 2021-04-27 17:35:41+05:30 Cprogrammer
# use at command to run update
#
# Revision 1.22 2021-04-27 15:51:18+05:30 Cprogrammer
# create HOME variable for update service
# removed daemontools from auto-update
#
# Revision 1.21 2021-04-27 13:40:44+05:30 Cprogrammer
# added -q option to apt-get to reduce output
#
# Revision 1.20 2021-04-27 13:36:10+05:30 Cprogrammer
# skip upgrade of pistop when clients are connected to fserver service
#
# Revision 1.19 2021-04-27 12:48:58+05:30 Cprogrammer
# added update service
#
# Revision 1.18 2021-04-14 13:20:10+05:30 Cprogrammer
# fixed .options
#
# Revision 1.17 2021-04-14 09:47:14+05:30 Cprogrammer
# update variables only if changed
#
# Revision 1.16 2021-04-13 18:25:27+05:30 Cprogrammer
# do not overwrite POWER_OFF env variable
#
# Revision 1.15 2021-04-13 18:07:55+05:30 Cprogrammer
# added command line invocation in run header
#
# Revision 1.14 2021-04-13 17:49:38+05:30 Cprogrammer
# create variables/.options file
#
# Revision 1.13 2021-04-13 16:48:02+05:30 Cprogrammer
# fixed home variable
#
# Revision 1.12 2021-04-13 15:29:40+05:30 Cprogrammer
# backup file in fclient service
#
# Revision 1.11 2021-04-01 20:58:31+05:30 Cprogrammer
# do backup using backup script; start mpd of not running
#
# Revision 1.10 2021-04-01 20:52:13+05:30 Cprogrammer
# use absolute path in BACKUP env variable
#
# Revision 1.9 2021-02-25 15:42:57+05:30 Cprogrammer
# use relative path for variables to allow renaming of service directory
#
# Revision 1.8 2021-01-11 22:21:14+05:30 Cprogrammer
# create HOME environment variable
#
# Revision 1.7 2020-08-31 16:40:17+05:30 Cprogrammer
# fixed shutdown script
#
# Revision 1.6 2020-08-31 12:22:40+05:30 Cprogrammer
# added code to do backup during startup in fserver
#
# Revision 1.5 2020-08-29 17:12:50+05:30 Cprogrammer
# fixed shutdown script
#
# Revision 1.4 2020-08-29 16:01:45+05:30 Cprogrammer
# use bash for run file
#
# Revision 1.3 2020-08-28 22:44:00+05:30 Cprogrammer
# create shutdown script for fserver service
#
# Revision 1.2 2020-08-28 22:05:45+05:30 Cprogrammer
# fixed syntax error
#
# Revision 1.1 2020-08-28 17:17:26+05:30 Cprogrammer
# Initial revision
#