-
Notifications
You must be signed in to change notification settings - Fork 0
/
wslstart.sh
executable file
·86 lines (75 loc) · 1.85 KB
/
wslstart.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
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
#!/bin/bash
# this script (normally at /etc/wslstart.sh) will be executed by
# /usr/sbin/wslstart as user root
#
# use
# ln -sf `readlink -f wslstart.sh` /etc/wslstart.sh
# to create a softlink
FLAGF=/run/shm/wslstart.flag
WSLDEF=/etc/default/wslstart
WSLUSER=
WSL1STTIME="false"
if [ -r ${WSLDEF} ]
then
# read $WSLUSER from $WSLDEF
source ${WSLDEF}
fi
# /run/shm is tmpfs so it's clean when new WSL session starts
if [ ! -f ${FLAGF} ]
then
# assume this is the first wslstart.sh instance of this WSL session
echo "This is WSL session's first wslstart.sh instance, starting..."
WSL1STTIME="true"
touch ${FLAGF}
# It's also a good idea to use /run/shm as /tmp and /var/tmp, do this once:
# sudo mv /tmp /tmp0
# sudo mv /var/tmp /var/tmp0
#
# sudo ln -sf /run/shm /tmp
# sudo ln -sf /run/shm /var/tmp
# reboot WSL
# we need this file so logout() does not return error
touch /var/run/utmp
# run all scripts in /etc/wslstart.d as user 'root'
if [ -d /etc/wslstart.d ]
then
for i in /etc/wslstart.d/*.sh
do
if [ -x $i ]
then
$i
fi
done
unset i
fi
# if ${WSLUSER} has ~/.wslstart.sh, also run it as user ${WSLUSER}
if [ -n "${WSLUSER}" -a -x /home/${WSLUSER}/.wslstart.sh ]
then
echo "Running .wslstart.sh of user [${WSLUSER}]..."
sudo -u ${WSLUSER} /home/${WSLUSER}/.wslstart.sh
fi
else
echo "This is NOT WSL session's first wslstart.sh instance."
fi
# this part is always executed everytime wslstart invoked
# start some service(s)
# always check sshd service because it's crucial
SSHDPID=$(pgrep sshd)
if [ -n "$SSHDPID" ]
then
echo "sshd is already running"
else
service ssh restart
fi
# always check cron service because it's crucial
CRONPID=$(pgrep cron)
if [ -n "$CRONPID" ]
then
echo "cron is already running"
else
service cron restart
fi
# TODO: more crucial services...
# syslogd?
# monit?
# zerotier client?