我正在尝试使用以下脚本将 Geoserver 作为 systemd 服务启动:
(使用 ubuntu 16.04)
[Unit]
Description=Geoserver
After=network.target
[Service]
Type=simple
ExecStart=/home/ermis/geoserver/bin/startup.sh
ExecStop=/home/ermis/geoserver/bin/shutdown.sh
User=ermis
[Install]
WantedBy=multi-user.target
我在系统日志中收到此错误
systemd[1]: Starting Geoserver...
startup.sh[21823]: The GEOSERVER_HOME environment variable is not defined
systemd[1]: geoserver.service: Main process exited, code=exited, status=1/FAILURE
startup.sh[21823]: This environment variable is needed to run this program
startup.sh[21823]: Please set it to the directory where geoserver was installed
VM2 systemd[1]: geoserver.service: Failed with result 'exit-code'.
VM2 systemd[1]: Failed to start Geoserver.
我尝试在 /etc/environment 中输入 GEOSERVER_HOME,但仍然出现相同的错误。
我究竟做错了什么?
答案1
您可以将环境文件添加到服务定义中:
[Service]
EnvironmentFile=/etc/sysconfig/yourservice
然后创建该文件(实际路径由您决定)并在其中定义您的变量并重新加载您的服务定义:
sudo systemctl daemon-reload
现在您的服务应该使用环境变量。