如何在 Ubuntu 18.04 上设置 Tomcat 权限?

如何在 Ubuntu 18.04 上设置 Tomcat 权限?

我在我的 Ubuntu 18.04 上安装了 Tomcat。

sudo systemctl status tomcat

● tomcat.service - Tomcat 9 servlet container
   Loaded: loaded (/etc/systemd/system/tomcat.service; disabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Mon 2020-03-23 08:00:51 CET; 25s ago
  Process: 7620 ExecStop=/opt/tomcat/latest/bin/shutdown.sh (code=exited, status=1/FAILURE)
  Process: 7586 ExecStart=/opt/tomcat/latest/bin/startup.sh (code=exited, status=0/SUCCESS)

让我们使用 journalctl -xe 进行更深入的了解。输出:

-- Subject: Unit cups-browsed.service has finished start-up
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
-- 
-- Unit cups-browsed.service has finished starting up.
-- 
-- The start-up result is RESULT.
мар 23 07:59:53 miki rsyslogd[1286]:  [origin software="rsyslogd" swVersion="8.32.0" x-pid="1286" x-info="http://www.rsyslog.com"] rsyslogd was HUPed
мар 23 08:00:32 miki dbus-daemon[4552]: [session uid=1000 pid=4552] Activating via systemd: service name='org.gnome.Terminal' unit='gnome-terminal-server.service' requested by ':1.74' (uid=1000 pid=6386 c
мар 23 08:00:32 miki systemd[4419]: Starting GNOME Terminal Server...
-- Subject: Unit UNIT has begun start-up
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
-- 
-- Unit UNIT has begun starting up.
мар 23 08:00:32 miki dbus-daemon[4552]: [session uid=1000 pid=4552] Successfully activated service 'org.gnome.Terminal'
мар 23 08:00:32 miki systemd[4419]: Started GNOME Terminal Server.
-- Subject: Unit UNIT has finished start-up
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
-- 
-- Unit UNIT has finished starting up.
-- 
-- The start-up result is RESULT.
мар 23 08:00:46 miki anacron[1187]: Job `cron.daily' terminated
мар 23 08:00:46 miki anacron[1187]: Normal exit (1 job run)
мар 23 08:00:51 miki sudo[7583]:     miki : TTY=pts/0 ; PWD=/home/miki ; USER=root ; COMMAND=/bin/systemctl start tomcat
мар 23 08:00:51 miki sudo[7583]: pam_unix(sudo:session): session opened for user root by (uid=0)
мар 23 08:00:51 miki systemd[1]: Starting Tomcat 9 servlet container...
-- Subject: Unit tomcat.service has begun start-up
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
-- 
-- Unit tomcat.service has begun starting up.
мар 23 08:00:51 miki startup.sh[7586]: Existing PID file found during start.
мар 23 08:00:51 miki startup.sh[7586]: Removing/clearing stale PID file.
мар 23 08:00:51 miki startup.sh[7586]: Tomcat started.
мар 23 08:00:51 miki systemd[1]: Started Tomcat 9 servlet container.
-- Subject: Unit tomcat.service has finished start-up
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
-- 
-- Unit tomcat.service has finished starting up.
-- 
-- The start-up result is RESULT.
мар 23 08:00:51 miki sudo[7583]: pam_unix(sudo:session): session closed for user root
мар 23 08:00:51 miki shutdown.sh[7620]: PID file found but either no matching process was found or the current user does not have permission to stop the process. Stop aborted.
мар 23 08:00:51 miki systemd[1]: tomcat.service: Control process exited, code=exited status=1
мар 23 08:00:51 miki systemd[1]: tomcat.service: Failed with result 'exit-code'.

如何修复此权限问题?

我配置了/etc/systemd/system/tomcat.service

[Unit]
Description=Tomcat 9 servlet container
After=network.target

[Service]
Type=forking

User=tomcat
Group=tomcat

Environment="JAVA_HOME=/usr/bin/java"
Environment="JAVA_OPTS=-Djava.security.egd=file:///dev/urandom -Djava.awt.headless=true"

Environment="CATALINA_BASE=/opt/tomcat/apache-tomcat-9.0.33"
Environment="CATALINA_HOME=/opt/tomcat/apache-tomcat-9.0.33"
Environment="CATALINA_PID=/opt/tomcat/apache-tomcat-9.0.33/temp/tomcat.pid"
Environment="CATALINA_OPTS=-Xms512M -Xmx1024M -server -XX:+UseParallelGC"

ExecStart=/opt/tomcat/latest/bin/startup.sh
ExecStop=/opt/tomcat/latest/bin/shutdown.sh

[Install]
WantedBy=multi-user.target

如何检查为什么没有找到匹配的进程或者当前用户没有权限停止该进程?

相关内容