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

enabling a new service in ubuntu 17.04

· 52CE 我爱测

I used the suggested answer from this post to make a custom service in my ubuntu 17.04 environment: Installing gitblit GO as service in Ubuntu Server 16.04 Unfortunately when I hit sudo systemctl enable gitblit_server.service I r…

问题原文

原帖链接 · Max · CC BY-SA 3.0

I used the suggested answer from this post to make a custom service in my ubuntu 17.04 environment: Installing gitblit GO as service in Ubuntu Server 16.04

Unfortunately when I hit

sudo systemctl enable gitblit_server.service

I receive

Failed to enable unit: File gitblit_server.service: Invalid argument

as an error.

Any idea what I am doing wrong?


Update:

result for journalctl -xe

Sep 01 16:06:22 git-dmz01 sudo[7121]: msoadmin : TTY=pts/1 ; PWD=/etc/systemd/system ; USER=root ; COMMAND=/bin/systemctl enable gitblit_server.service
Sep 01 16:06:22 git-dmz01 sudo[7121]: pam_unix(sudo:session): session opened for user root by msoadmin(uid=0)
Sep 01 16:06:22 git-dmz01 systemd[1]: [/etc/systemd/system/gitblit_server.service:12] Missing '='.
Sep 01 16:06:22 git-dmz01 sudo[7121]: pam_unix(sudo:session): session closed for user root

content of my file gitblit_server.service:

[Unit]
   Description=gitblit Server CVS
   After=network.target
[Service]
   User=msoadmin
   Type=simple
   WorkingDirectory=/opt/gitblit
   PIDFile=/var/run/gitblit.service.pid
   ExecStartPre=/opt/gitblit/java-proxy-config.sh
   ExecStart=/usr/bin/java -server -Xmx1024M -Djava.awt.headless=true -jar
   /opt/gitblit/gitblit.jar --baseFolder /opt/gitblit/data --dailyLogFile

[Install]
   WantedBy=multi-user.target

已采纳解答

原帖链接 · Valentin Bajrami · CC BY-SA 3.0

You are using the wrong answer to create custom services. To start with, custom service files should not be placed within /lib/systemd/system rather you'd use /etc/systemd/system/your_custom_file.service.

Secondly, after creating the service file you'd run systemct daemon-reload to notify systemd about your newly created file. Make sure you've restored SELinux file context using restorecon -RFvv /etc/systemd/system

After the update, the answer is obvious.

[Service]
.....
....
ExecStart=/usr/bin/java -server -Xmx1024M -Djava.awt.headless=true -jar
   /opt/gitblit/gitblit.jar --baseFolder /opt/gitblit/data --dailyLogFile
....

Here, the line that starts with /opt/gitblit/.. is treated as a single line and not part of ExecStart directive which is causing the error. You could simply fix it using a backslash as follows:

ExecStart=/usr/bin/java -server -Xmx1024M -Djava.awt.headless=true -jar \
   /opt/gitblit/gitblit.jar --baseFolder /opt/gitblit/data --dailyLogFile

Finally run:

systemctl daemon-reload && systemctl enable gitblit_server.service

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

资料来源与适用范围

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

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

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