Add an rc.d script for NetBSD.
[akkoma] / installation / netbsd / rc.d / pleroma
1 #!/bin/sh
2 # PROVIDE: pleroma
3 # REQUIRE: DAEMON pgsql
4
5 if [ -f /etc/rc.subr ]; then
6 . /etc/rc.subr
7 fi
8
9 name="pleroma"
10 rcvar=${name}
11 command="/usr/pkg/bin/elixir"
12 command_args="/usr/pkg/bin/mix phx.server &"
13 start_cmd=pleroma_start
14 start_precmd="ulimit -n unlimited"
15 pidfile="${pleroma_home}/pleroma/pid"
16
17 pleroma_chdir="${pleroma_home}/pleroma"
18 pleroma_env="HOME=${pleroma_home} MIX_ENV=prod"
19 pleroma_user="pleroma"
20
21 pleroma_start()
22 {
23 echo "Starting ${name}."
24 ${start_precmd}
25 su -m ${pleroma_user} -c "cd ${pleroma_chdir} && \
26 ${pleroma_env} ${command} ${command_args}"
27 echo $! > ${pidfile}
28 }
29
30 check_pidfile()
31 {
32 read _pid _junk < ${pidfile}
33 echo -n "$(ps -axo pid | grep ${_pid})"
34 }
35
36 if [ -f /etc/rc.subr -a -d /etc/rc.d -a -f /etc/rc.d/DAEMON ]; then # newer NetBSD
37 load_rc_config ${name}
38 run_rc_command "$1"
39 else # ancient NetBSD, Solaris and illumos, Linux, etc...
40 cmd=${1:-start}
41
42 case ${cmd} in
43 start)
44 echo "Starting ${name}."
45 ${start_cmd}
46 ;;
47
48 stop)
49 echo "Stopping ${name}."
50 kill `cat ${pidfile}`
51 rm ${pidfile}
52 ;;
53
54 restart)
55 ( $0 stop )
56 sleep 5
57 $0 start
58 ;;
59
60 *)
61 echo 1>&2 "Usage: $0 [start|stop|restart]"
62 exit 1
63 ;;
64 esac
65 exit 0
66 fi