又耗时6天-解决JNOJ(江南OJ)判题机dispatcher在Ubuntu18.04.3中不能自动启动的问题

原创
2019/12/28 10:40
阅读数 911

环境

Windows server 2019中的 Ubuntu server 18.04.3LTS 是VM 虚拟机

JNOJ搭建安装记录见: 耗时6天-JNOJ(江南OJ)搭建、安装记录

问题现象  : 重启系统后终端提交后一直显示“等待测评”

       重新启动服务器系统后,终端提交代码一直“等待测评”(pending)中

当时临时的解决方法:

每次系统启动后,手动运行判题机一次。如下2条命令:

cd /home/judge/jnoj/judge
sudo ./dispatcher

 

又经过6天的折腾终于找到了一种解决方法

经过6天的折腾,安装了好多次JNOJ后,在网上文章的启发下终于解决了这个问题。

解决步骤如下:


samxiao@JNOJ:/home/judge/jnoj/judge$ sudo vi jnoj-judge.service
samxiao@JNOJ:/home/judge/jnoj/judge$ sudo vi jnoj-start-judge.sh
samxiao@JNOJ:/home/judge/jnoj/judge$ sudo chmod +x jnoj-start-judge.sh
samxiao@JNOJ:/home/judge/jnoj/judge$ sudo ln -s  /home/judge/jnoj/judge/jnoj-judge.service /etc/systemd/system/jnoj-judge.service
samxiao@JNOJ:/home/judge/jnoj/judge$ sudo systemctl  daemon-reload
samxiao@JNOJ:/home/judge/jnoj/judge$ sudo systemctl  enable jnoj-judge.service
Created symlink /etc/systemd/system/multi-user.target.wants/jnoj-judge.service → /home/judge/jnoj/judge/jnoj-judge.service.
samxiao@JNOJ:/home/judge/jnoj/judge$ sudo reboot

jnoj-judge.service的内容如下:

[Unit]
Description=Start JNOJ judge
#Requires=basic.target
After=network.target
#Wants=nginx
#AllowIsolate=yes

[Service]
ExecStart=-/home/judge/jnoj/judge/jnoj-start-judge.sh
RemainAfterExit=yes
#Type=simple
KillMod=control-group
#Restart=no #on-failure
#RestartSec=30

[Install]
WantedBy=multi-user.target

jnoj-start-judge.sh的内容如下:

#!/bin/bash
sleep 3
cd /home/judge/jnoj/judge
date >> shstart.log
./dispatcher
echo "... finished." >> shstart.log
exit 0

 

改过后的文件夹内容:

samxiao@JNOJ:/home/judge/jnoj/judge$ pwd
/home/judge/jnoj/judge
samxiao@JNOJ:/home/judge/jnoj/judge$ ll
total 156
drwxr-xr-x  7 root root  4096 Dec 28 10:06 ./
drwxr-xr-x 23 root root  4096 Dec 21 15:11 ../
lrwxrwxrwx  1 root root    42 Dec 21 15:15 0 -> /dev/shm/jnoj/home/judge/jnoj/judge/run/0//
-rw-r--r--  1 root root   858 Dec 21 15:11 config.ini
drwxrwxrwx  9 root root  4096 Dec 22 18:47 data/
-rwxr-xr-x  1 root root 25392 Dec 21 15:11 dispatcher*
drwxr-xr-x  2 root root  4096 Dec 21 15:11 etc/
-rw-r--r--  1 root root   309 Dec 28 09:52 jnoj-judge.service
-rwxr-xr-x  1 root root   123 Dec 28 10:05 jnoj-start-judge.sh*
-rwxr-xr-x  1 root root 80704 Dec 21 15:11 judge*
drwxrwxrwx  2 root root  4096 Dec 21 15:16 log/
-rwxr-xr-x  1 root root   524 Dec 21 15:11 makefile*
drwxrwxrwx  3 root root  4096 Dec 21 15:15 run/
-rw-r--r--  1 root root    86 Dec 28 10:11 shstart.log
drwxr-xr-x  2 root root  4096 Dec 21 15:11 src/
samxiao@JNOJ:/home/judge/jnoj/judge$
samxiao@JNOJ:/home/judge/jnoj/judge$
samxiao@JNOJ:/home/judge/jnoj/judge$ cat jnoj-judge.service
[Unit]
Description=Start JNOJ judge
#Requires=basic.target
After=network.target
#Wants=nginx
#AllowIsolate=yes

[Service]
ExecStart=-/home/judge/jnoj/judge/jnoj-start-judge.sh
RemainAfterExit=yes
#Type=simple
KillMod=control-group
#Restart=no #on-failure
#RestartSec=30

[Install]
WantedBy=multi-user.target

samxiao@JNOJ:/home/judge/jnoj/judge$
samxiao@JNOJ:/home/judge/jnoj/judge$
samxiao@JNOJ:/home/judge/jnoj/judge$
samxiao@JNOJ:/home/judge/jnoj/judge$ cat jnoj-start-judge.sh
#!/bin/bash
sleep 3
cd /home/judge/jnoj/judge
date >> shstart.log
./dispatcher
echo "... finished." >> shstart.log
exit 0

samxiao@JNOJ:/home/judge/jnoj/judge$

参考文章

  1. ubuntu18.04 使用systemd方式添加开机运行sh脚本
  2. Systemd 入门教程:实战篇
展开阅读全文
打赏
0
0 收藏
分享
加载中
SamXIAO博主
此方法对Ubuntu 17, 18应该适用。对Ubuntu16及更早的版本不适用。
2019/12/28 11:11
回复
举报
SamXIAO博主
写此博文用时2小时
2019/12/28 10:53
回复
举报
更多评论
打赏
2 评论
0 收藏
0
分享
返回顶部
顶部