我想在Archlinux(systemd)启动时运行一个简单的命令:
nohup fatrat -n &
我已经在Debian上工作了:
#! /bin/sh
# /etc/init.d/fatratWS
### BEGIN INIT INFO
# Provides: fatratWS
# Required-Start: $network $local_fs $remote_fs
# Required-Stop: $network $local_fs $remote_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: fatratWS init script.
# Description: Starts and stops fatrat Web Server services.
### END INIT INFO
#VAR
FATRAT_PID=$(ps aux | awk '/fatrat --nogui/ && !/awk/ && !/nohup/ {print $2}')
# Carry out specific functions when asked to by the system
case "$1" in
start)
echo "Starting script fatratWS"
if [ -z "$FATRAT_PID" ]; then
nohup fatrat --nogui &
echo "Started"
else
echo "fatratWS already started"
fi
;;
stop)
echo "Stopping script fatratWS"
if [ ! -z "$FATRAT_PID" ]; then
kill $FATRAT_PID
fi
echo "OK"
;;
status)
if [ ! -z "$FATRAT_PID" ]; then
echo "The fatratWS is running with PID = "$FATRAT_PID
else
echo "No process found for fatratWS"
fi
;;
*)
echo "Usage: /etc/init.d/fatratWS {start|stop|status}"
exit 1
;;
esac
exit 0
如何在Arch上实现相同目标?
我试过了:
[Unit]
Description=Fatrat NoGui Web Access Service
[Service]
ExecStart=/usr/bin/nohup /usr/bin/fatrat -n &
Type=forking
[Install]
WantedBy=multi-user.target
但是手动启动时无法启动(超时)
User=my_user_name
下添加[Service]
以用户身份运行该应用程序。这样,应用程序可以从/home/my_user_name/.local/share/fatrat/data