Add persistent storage in CMDS_DIR/data
This commit is contained in:
		
							parent
							
								
									47425fdd85
								
							
						
					
					
						commit
						e6d32c5cab
					
				
							
								
								
									
										9
									
								
								cmds/count
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										9
									
								
								cmds/count
									
									
									
									
									
										Executable file
									
								
							| @ -0,0 +1,9 @@ | |||||||
|  | #!/usr/bin/env bash | ||||||
|  | 
 | ||||||
|  | DIR=$(dirname -- $0) | ||||||
|  | DATA="$DIR/data/count" | ||||||
|  | 
 | ||||||
|  | old_number=$(cat "$DATA") | ||||||
|  | new_number=$((old_number + 1)) | ||||||
|  | echo $new_number > $DATA | ||||||
|  | echo $new_number | ||||||
							
								
								
									
										2
									
								
								cmds/data/.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										2
									
								
								cmds/data/.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @ -0,0 +1,2 @@ | |||||||
|  | * | ||||||
|  | !.gitignore | ||||||
							
								
								
									
										18
									
								
								our.example.service
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										18
									
								
								our.example.service
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,18 @@ | |||||||
|  | [Unit] | ||||||
|  | Description=our | ||||||
|  | After=our.service | ||||||
|  | 
 | ||||||
|  | [Service] | ||||||
|  | Type=simple | ||||||
|  | WorkingDirectory=/home/kindrobot/spacework/our | ||||||
|  | ExecStart=/home/kindrobot/spacework/our/our.rb | ||||||
|  | Environment="OUR_NICK=your" | ||||||
|  | Environment="OUR_CHANNELS=#bots" | ||||||
|  | Environment="OUR_CMDS_DIR=/home/kindrobot/spacework/our/cmds/" | ||||||
|  | Restart=always | ||||||
|  | RestartSec=5 | ||||||
|  | StartLimitInterval=60s | ||||||
|  | StartLimitBurst=3 | ||||||
|  | 
 | ||||||
|  | [Install] | ||||||
|  | WantedBy=default.target | ||||||
							
								
								
									
										10
									
								
								our.rb
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								our.rb
									
									
									
									
									
								
							| @ -3,9 +3,10 @@ require 'socket' | |||||||
| require 'open3' | require 'open3' | ||||||
| 
 | 
 | ||||||
| # configurable environment variables | # configurable environment variables | ||||||
| nick     = ENV['OUR_NICK']     || 'our' | nick      = ENV['OUR_NICK']      || 'our' | ||||||
| channels = ENV['OUR_CHANNELS'] || '#tildetown,#bots' | channels  = ENV['OUR_CHANNELS']  || '#tildetown,#bots' | ||||||
| prefix   = ENV['OUR_PREFIX']   || "#{nick}/" | prefix    = ENV['OUR_PREFIX']    || "#{nick}/" | ||||||
|  | cmds_dir  = ENV['OUR_CMDS_DIR']  || '/town/our' | ||||||
| 
 | 
 | ||||||
| module IRC | module IRC | ||||||
| 
 | 
 | ||||||
| @ -82,8 +83,9 @@ i.hook do |msg| | |||||||
|   target, content = msg.args |   target, content = msg.args | ||||||
|   next unless content.delete_prefix! prefix |   next unless content.delete_prefix! prefix | ||||||
| 
 | 
 | ||||||
|  | 
 | ||||||
|   cmd, args = content.split(' ', 2)   |   cmd, args = content.split(' ', 2)   | ||||||
|   cmd = '/town/our/' + cmd |   cmd = "#{cmds_dir}/#{cmd}" | ||||||
|   args ||= '' |   args ||= '' | ||||||
|   next unless File.exists? cmd |   next unless File.exists? cmd | ||||||
|   if not File.executable? cmd |   if not File.executable? cmd | ||||||
|  | |||||||
							
								
								
									
										11
									
								
								start.sh
									
									
									
									
									
								
							
							
						
						
									
										11
									
								
								start.sh
									
									
									
									
									
								
							| @ -1,4 +1,13 @@ | |||||||
| #!/usr/bin/env bash | #!/usr/bin/env bash | ||||||
| 
 | 
 | ||||||
| DIR=$(dirname -- $0) | DIR=$(dirname -- $0) | ||||||
| /usr/bin/bwrap --unshare-all --ro-bind / / --share-net --dev /dev --tmpfs /tmp $DIR/our.rb | OUR_CMDS_DIR=${OUR_CMDS_DIR:-/town/our} | ||||||
|  | 
 | ||||||
|  | /usr/bin/bwrap \ | ||||||
|  | 	--unshare-all \ | ||||||
|  | 	--ro-bind / / \ | ||||||
|  | 	--bind "$OUR_CMDS_DIR/data" "$OUR_CMDS_DIR/data" \ | ||||||
|  | 	--share-net \ | ||||||
|  | 	--dev /dev \ | ||||||
|  | 	--tmpfs /tmp \ | ||||||
|  | 	$DIR/our.rb | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user