AutoRun McMyAdmin at reboot/start (Linux/Ubuntu)
1. Login as root, create a file as
vim /etc/init.d/McMyAdmin.sh
2. Copy and paste the following content into it
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
#!/bin/sh # /etc/init.d/McMyAdmin # version 0.0.1 2014-11-24 ### BEGIN INIT INFO # Provides: McMyAdmin # Required-Start: $local_fs $remote_fs screen-cleanup $syslog # Required-Stop: $local_fs $remote_fs $syslog # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: Start McMyAdmin at boot # Description: Start McMyAdmin at boot. ### END INIT INFO #Settings USERNAME='mcserver' SERVICE='McMyAdmin' MCAPATH="/home/$USERNAME/McMyAdmin" INVOCATION="cd $MCAPATH && screen -dmS $SERVICE ./MCMA2_Linux_x86_64" ME="$(whoami)" as_user() { if [ "$ME" = "$USERNAME" ] ; then bash -c "$1" else su - "$USERNAME" -c "$1" fi } case "$1" in start) if pgrep -u $USERNAME -f $SERVICE > /dev/null then echo "McMyAdmin is already started on screen McMyAdmin" else echo "Starting $SERVICE ..." cd $MCAPATH as_user "$INVOCATION" sleep 7 if pgrep -u $USERNAME -f $SERVICE > /dev/null then echo "McMyAdmin started on screen $SERVICE" else echo "Error! Could not start $SERVICE" fi fi ;; stop) if pgrep -u $USERNAME -f $SERVICE > /dev/null then echo "Stopping $SERVICE..." as_user "screen -X -S $SERVICE kill" sleep 7 else echo "$SERVICE was not running." fi if pgrep -u $USERNAME -f $SERVICE -a > /dev/null then echo "Error! $SERVICE could not be stopped." else echo "$SERVICE is stopped." fi ;; *) echo "Usage: /etc/init.d/McMyAdmin_autostart {start|stop}" exit 1 ;; esac exit 0 |
Pleae note that you need to adjust the USERNAME and MCAPATH.
3. :wq
to save and quit
4. Change the mode of the file
chmod +x /etc/init.d/McMyAdmin.sh
5. create soft link to startup
update-rc.d McMyAdmin.sh defaults 99
Note that you can remove it by
update-rc.d -f McMyAdmin.sh remove
6. reboot to test.
7. If it is not work, try to run as root, with the following command
/etc/init.d/McMyAdmin start
本作品采用创作共用版权协议, 要求署名、非商业用途和保持一致. 转载本站内容必须也遵循署名-非商业用途-保持一致的创作共用协议.
发表回复