-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmake-as-service.sh
executable file
·57 lines (40 loc) · 1.14 KB
/
make-as-service.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
57
#!/usr/bin/env bash
MEDIA_SERVER_CONFIG_FILE=/etc/init/mediaServer.conf
MEDIA_SERVER_SERVICE_FILE=/lib/systemd/system/mediaServer.service
mkdir -p /etc/init/
echo "Make $MEDIA_SERVER_CONFIG_FILE"
if [ -f "$MEDIA_SERVER_CONFIG_FILE" ]; then
echo "Delete old $MEDIA_SERVER_CONFIG_FILE file"
rm $MEDIA_SERVER_CONFIG_FILE
fi
cat <<EOT >> $MEDIA_SERVER_CONFIG_FILE
description "mediaServer"
start on stopped rc RUNLEVEL=[2345]
respawn
exec sh /home/mediaServer/mediaServer.sh
EOT
echo "Make $MEDIA_SERVER_SERVICE_FILE"
if [ -f "$MEDIA_SERVER_SERVICE_FILE" ]; then
echo "Delete old $MEDIA_SERVER_SERVICE_FILE file"
rm $MEDIA_SERVER_SERVICE_FILE
fi
cat <<EOT >> $MEDIA_SERVER_SERVICE_FILE
[Unit]
Description=Media Server
[Install]
WantedBy=multi-user.target
[Service]
AmbientCapabilities=CAP_SYS_RAWIO
User=nobody
WorkingDirectory=/home/mediaServer/mediaServer
ExecStart=/home/mediaServer/mediaServer.sh
TimeoutSec=600
Restart=on-failure
RuntimeDirectoryMode=755
SyslogIdentifier=mediaServer
EOT
cd /home/mediaServer/
chmod +x mediaServer.sh
echo "Start service mediaServer"
sudo service mediaServer start
sudo service mediaServer status