大网数据广告活动
服务器运维问答

Service failed to start because ernvironment variable is missing

· 52CE 我爱测

I am trying to start Geoserver as a systemd service using this script: (using ubuntu 16.04) [Unit] Description=Geoserver After=network.target [Service] Type=simple ExecStart=/home/ermis/geoserver/bin/startup.sh ExecStop=/home/erm…

问题原文

原帖链接 · xpanta · CC BY-SA 4.0

I am trying to start Geoserver as a systemd service using this script:

(using 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

And I get this error in syslog

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.

I tried to enter GEOSERVER_HOME in /etc/environment but I still get the same error.

What am I doing wrong?

已采纳解答

原帖链接 · Gerald Schneider · CC BY-SA 4.0

You can add an environment file to your service definition:

[Service]
EnvironmentFile=/etc/sysconfig/yourservice

Then create that file (the actual path is up to you) and define your variable there and reload your service definitions:

sudo systemctl daemon-reload

Now the environment variables should be used by your service.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2019-12-05)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。